fix(runtime): importing custom elements build in lazy build #3330
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm test
) were run locally and passednpm run test.karma.prod
) were run locally and passednpm run prettier
) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
You are unable to import and use a custom elements build within a lazy-hydrated bundle Stencil project. When trying to use a Stencil compiled library within another Stencil project, you will receive numerous exceptions & the component will fail to render.
GitHub Issue Number: #2531, #3233
What is the new behavior?
Stencil libraries can be consumed within other Stencil libraries. For example, developers can use
@ionic/core/components
within their own Stencil libraries.$customElement$
flag on the compiler metadata for the component, so that the runtime can make decisions based on if the component being rendered is a custom element or part of the lazy/hydrated build.Does this introduce a breaking change?
Testing
You can either clone this repository: https://github.com/sean-perkins/stencil-ce-project or follow these steps:
npm stencil init
@ionic/core
stencil.config.ts
to use the global script:Other information
These changes were inspired from MarkChrisLevy's fork: https://github.com/CODE-AND-MORE/stencil/commits/codeandmore-2.12.1 and tested in an isolated project. After running into the issue and diagnosing a solution, I found that my approach aligned extremely similar to his.
There is likely additional considerations that need to take place to handle mixing custom elements & the hydrated build, but the current state is completely broken, incrementally improving the experience to initialize the components seems valuable to the community. Also by fixing this issue, I will be able to identify other issues with the build and work to report and resolve those.