lit / lit/lit

[context] Rendering a manually created context provider element in a consumer that is a light DOM child of a provider causes an infinite loop

Open
#5,221 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
21.8k
Forks
1.1k
Avg merge
18h 25m
Merged PRs (30d)
2

Description

### Which package(s) are affected?

Context (@lit/context)

### Description

Given a tree like the following:
```html

#shadow-root
|

#shadow-root
|
|
|

```
Consumer gets stuck in an infinite loop rerendering itself.

From my basic investigation, it appears to be caused by the `context-provider` event, but beyond that I don't know what causes it

### Reproduction

https://lit.dev/playground/#sample=examples%2Fhello-world&gist=14a287d908738aa5664a99a88c3dd561

### Workaround

Stopping propagation of the `context-provider` event via either `stopPropagation` or `stopImmediatePropagation` on the consumer element causes the issue to disappear

### Is this a regression?

No or unsure. This never worked, or I haven't tried before.

### Affected versions

lit@3.3.1, @lit/context@1.1.6

### Browser/OS/Node environment

Browser: Librewolf 144.0-1
OS: Linux

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 with the linked Lit Playground reproduction and the @lit/context package at the reported lit@3.3.1 and @lit/context@1.1.6 versions. Trace dispatch and handling of the context-provider event when a manually created provider is rendered by a light-DOM consumer, then verify that the consumer no longer rerenders indefinitely without requiring event propagation to be stopped.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.