lit / lit/lit.dev

[doc] Document `context` packages ContextRoot

Open
#1,185 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
142
Forks
230
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ContextRoot documentation page linked in the issue and read the existing API section alongside the linked playground example. Add introductory guidance explaining why to use ContextRoot, the element or import-order problem it addresses, and its tradeoffs; done means the page clearly prepares readers before the API reference.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.