lit / lit/lit

[reactive-element] queryAssignedElements is initially empty

Open
#3,706 6 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
21.8k
Forks
1.1k
Avg merge
18h 25m
Merged PRs (30d)
2

Description

### Which package(s) are affected?

Lit Core (lit / lit-html / lit-element / reactive-element)

### Description

`queryAssignedElements` is initially empty when a slot is used.

```
@queryAssignedElements({ slot: 'foo' })
fooEl!: Array;
```

Add an intital value for that slot:

```

foo

```

`this.fooEl.length` is `0`.

### Reproduction

[Example in Playground](https://lit.dev/playground/#project=W3sibmFtZSI6InNpbXBsZS1ncmVldGluZy50cyIsImNvbnRlbnQiOiJpbXBvcnQge2h0bWwsIGNzcywgTGl0RWxlbWVudH0gZnJvbSAnbGl0JztcbmltcG9ydCB7Y3VzdG9tRWxlbWVudCwgcHJvcGVydHksIHF1ZXJ5QXNzaWduZWRFbGVtZW50c30gZnJvbSAnbGl0L2RlY29yYXRvcnMuanMnO1xuXG5AY3VzdG9tRWxlbWVudCgnc2ltcGxlLWdyZWV0aW5nJylcbmV4cG9ydCBjbGFzcyBTaW1wbGVHcmVldGluZyBleHRlbmRzIExpdEVsZW1lbnQge1xuICBzdGF0aWMgc3R5bGVzID0gY3NzYHAgeyBjb2xvcjogYmx1ZSB9YDtcblxuICBAcHJvcGVydHkoKVxuICBuYW1lID0gJ1NvbWVib2R5JztcbiAgXG4gIEBxdWVyeUFzc2lnbmVkRWxlbWVudHMoeyBzbG90OiAnZm9vJyB9KVxuICBmb29FbCE6IEFycmF5PEhUTUxFbGVtZW50PjsgIFxuICBcblxuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIGh0bWxgPHA-SGVsbG8sICR7dGhpcy5uYW1lfSE8L3A-PHNsb3QgbmFtZT1cImZvb1wiPjwvc2xvdD4ke3RoaXMuZm9vRWwubGVuZ3RofWA7XG4gIH1cbn1cbiJ9LHsibmFtZSI6ImluZGV4Lmh0bWwiLCJjb250ZW50IjoiPCFET0NUWVBFIGh0bWw-XG48aGVhZD5cbiAgPHNjcmlwdCB0eXBlPVwibW9kdWxlXCIgc3JjPVwiLi9zaW1wbGUtZ3JlZXRpbmcuanNcIj48L3NjcmlwdD5cbjwvaGVhZD5cbjxib2R5PlxuICA8c2ltcGxlLWdyZWV0aW5nIG5hbWU9XCJXb3JsZFwiPjxkaXYgc2xvdD1cImZvb1wiPmZvbzwvZGl2Pjwvc2ltcGxlLWdyZWV0aW5nPlxuPC9ib2R5PlxuIn0seyJuYW1lIjoicGFja2FnZS5qc29uIiwiY29udGVudCI6IntcbiAgXCJkZXBlbmRlbmNpZXNcIjoge1xuICAgIFwibGl0XCI6IFwiXjIuMC4wXCIsXG4gICAgXCJAbGl0L3JlYWN0aXZlLWVsZW1lbnRcIjogXCJeMS4wLjBcIixcbiAgICBcImxpdC1lbGVtZW50XCI6IFwiXjMuMC4wXCIsXG4gICAgXCJsaXQtaHRtbFwiOiBcIl4yLjAuMFwiXG4gIH1cbn0iLCJoaWRkZW4iOnRydWV9XQ)

### Workaround

Triggering manually a `document.querySelector('simple-greeting').requestUpdate()` gives the expected result.

### Is this a regression?

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

### Affected versions

2.6.1

### Browser/OS/Node environment

-

Contributor guide

Open the contributing guide

Research direction

Start with the reactive-element queryAssignedElements decorator and reproduce the initial slotted-element case in the linked Lit Playground. Trace why the value is empty before requestUpdate(), then verify that the initial value contains the assigned

without the manual workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.