Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(customElementRegistry): add carbonElement decorator #10080

Conversation

andy-blum
Copy link
Contributor

Related Ticket(s)

Closes #9940

Description

This PR takes a new approach, and offers some advantages of #9941.

While the other PR aims to separate class definitions from their registration in the browser, and should work well for teams or projects that wish to extend C4IBM components, it does nothing to solve the problem for teams that are double-consuming C4IBM components. For example, consider the widget team:

  • They are building widgets using the react-wrapper version of the components
  • When the react component imports the element, it brings along its customElements.define() method
  • The widget is placed on a page that is already using the C4IBM CDN links, which also bring along the customElements.define() method.
  • Both the widget script and the CDN link are rolled up into separate scripts and whichever one runs second will encounter the unexpected error, not know how to handle that problem, and halt execution of the script, likely leaving large pieces of setup functionality unprocessed

This new approach offers a method for elements to attempt to define themselves, but to gracefully handle the failure and to continue executing the remainder of the running script. The new decorator is a simple copy/paste from the LitElement @customElement decorator, with the customElements.define functions wrapped in a try/catch block.

As of right now, this only impacts one component and is simply a proof-of-concept.

Changelog

New

  • Adds a @carbonElement() decorator to the carbon-web-components package

Changed

  • Edit the carbon-web-components package's accordion-item component to use @CarbonElement

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Feb 22, 2023

@ibmdotcom-bot
Copy link
Contributor

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Feb 22, 2023

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Feb 22, 2023

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Feb 22, 2023

@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Feb 22, 2023

@andy-blum
Copy link
Contributor Author

Additional context around why this isn't a part of the lit framework:

lit/lit#1812

@proeung proeung requested a review from kennylam February 22, 2023 20:35
@proeung proeung added package: web components Work necessary for the IBM.com Library web components package 👀 eyes needed labels Feb 22, 2023
@proeung
Copy link
Contributor

proeung commented Mar 7, 2023

@kennylam @IgnacioBecerra We'd love to get your thoughts on this new decorator approach for the custom element registry errors (#9940).

@ibmdotcom-bot
Copy link
Contributor

@proeung
Copy link
Contributor

proeung commented Mar 21, 2023

@kennylam @annawen1 Feel free to close out this PR, if the edit made to the rollup config (#10209) fixes the custom registry error.

@andy-blum andy-blum changed the base branch from main to release/v1.45.0 March 22, 2023 13:44
@andy-blum andy-blum added the test: CDN preview used for generating @carbon/ibmdotcom-web-components CDN for testing label Mar 22, 2023
@andy-blum andy-blum closed this Mar 22, 2023
@andy-blum andy-blum reopened this Mar 22, 2023
@ibmdotcom-bot
Copy link
Contributor

ibmdotcom-bot commented Mar 22, 2023

@andy-blum andy-blum closed this Mar 24, 2023
@andy-blum andy-blum reopened this Mar 24, 2023
@andy-blum andy-blum requested review from annawen1 and emyarod March 24, 2023 15:47
@ibmdotcom-bot
Copy link
Contributor

Copy link
Member

@emyarod emyarod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

@emyarod emyarod added the Ready to merge Label for the pull requests that are ready to merge label Mar 27, 2023
@kodiakhq kodiakhq bot merged commit 3020c95 into carbon-design-system:release/v1.45.0 Mar 27, 2023
kennylam pushed a commit to kennylam/carbon-for-ibm-dotcom that referenced this pull request Dec 4, 2023
…ign-system#10080)

### Related Ticket(s)

Closes carbon-design-system#9940 

### Description

This PR takes a new approach, and offers some advantages of carbon-design-system#9941.

While the other PR aims to separate class definitions from their registration in the browser, and should work well for teams or projects that wish to _extend_ C4IBM components, it does nothing to solve the problem for teams that are _double-consuming_ C4IBM components. For example, consider the widget team:

- They are building widgets using the react-wrapper version of the components
- When the react component imports the element, it brings along its `customElements.define()` method
- The widget is placed on a page that is already using the C4IBM CDN links, which _also_ bring along the `customElements.define()` method.
- Both the widget script and the CDN link are rolled up into separate scripts and whichever one runs second will encounter the unexpected error, not know how to handle that problem, and halt execution of the script, likely leaving large pieces of setup functionality unprocessed

This new approach offers a method for elements to _attempt_ to define themselves, but to gracefully handle the failure and to continue executing the remainder of the running script. The new decorator is a simple copy/paste from the LitElement `@customElement` decorator, with the `customElements.define` functions wrapped in a try/catch block.

As of right now, this only impacts one component and is simply a proof-of-concept.

### Changelog

**New**

- Adds a `@carbonElement()` decorator to the carbon-web-components package

**Changed**

- Edit the carbon-web-components package's accordion-item component to use @CarbonElement
kennylam pushed a commit to kennylam/carbon-for-ibm-dotcom that referenced this pull request Jun 11, 2024
…ign-system#10080)

### Related Ticket(s)

Closes carbon-design-system#9940 

### Description

This PR takes a new approach, and offers some advantages of carbon-design-system#9941.

While the other PR aims to separate class definitions from their registration in the browser, and should work well for teams or projects that wish to _extend_ C4IBM components, it does nothing to solve the problem for teams that are _double-consuming_ C4IBM components. For example, consider the widget team:

- They are building widgets using the react-wrapper version of the components
- When the react component imports the element, it brings along its `customElements.define()` method
- The widget is placed on a page that is already using the C4IBM CDN links, which _also_ bring along the `customElements.define()` method.
- Both the widget script and the CDN link are rolled up into separate scripts and whichever one runs second will encounter the unexpected error, not know how to handle that problem, and halt execution of the script, likely leaving large pieces of setup functionality unprocessed

This new approach offers a method for elements to _attempt_ to define themselves, but to gracefully handle the failure and to continue executing the remainder of the running script. The new decorator is a simple copy/paste from the LitElement `@customElement` decorator, with the `customElements.define` functions wrapped in a try/catch block.

As of right now, this only impacts one component and is simply a proof-of-concept.

### Changelog

**New**

- Adds a `@carbonElement()` decorator to the carbon-web-components package

**Changed**

- Edit the carbon-web-components package's accordion-item component to use @CarbonElement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 eyes needed package: web components Work necessary for the IBM.com Library web components package Ready to merge Label for the pull requests that are ready to merge test: CDN preview used for generating @carbon/ibmdotcom-web-components CDN for testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[web-components]: prevent custom element registry errors
4 participants