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

[doc] Document context packages ContextRoot #1185

Open
AndrewJakubowicz opened this issue Sep 15, 2023 · 0 comments
Open

[doc] Document context packages ContextRoot #1185

AndrewJakubowicz opened this issue Sep 15, 2023 · 0 comments

Comments

@AndrewJakubowicz
Copy link
Contributor

While making the basic context example I ran into a footgun with element upgrade order or import order.

I made this example: https://lit.dev/playground/#gist=3ddd4d9368a408508f88a5ae328478a3

However due to the timing of component upgrading, the provider didn't work inside the <slot>, which confused me.

Having two script imports in the example fixed the issue, e.g.:

  <script type="module" src="provider-element.js"></script>
  <script type="module" src="consumer-element.js"></script>

But swapping the imports would again break the slotted consumer.

The fix for this situation is to add a ContextRoot and attach it to document.body.

Solution

ContextRoot is already documented: https://lit.dev/docs/data/context/#contextroot, however I think it could use some documentation above the API section with why you should use it and the tradeoffs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant