-
Notifications
You must be signed in to change notification settings - Fork 1k
@query and @queryAll return null or [] before first update #2065
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
Conversation
Fixes #2062. To match Lit1 behavior, the `@query` decorator returns `null` (rather than `undefined`) if a decorated property is accessed before first update. Likewise, a `@queryAll` decorated property returns `[]` rather than `undefined`.
🦋 Changeset detectedLatest commit: 12d4c74 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultslit-element-list
render
update
update-reflect
lit-html-kitchen-sink
render
update
nop-update
lit-html-repeat
render
update
lit-html-template-heavy
render
update
reactive-element-list
render
update
update-reflect
|
| return ( | ||
| (this as unknown as {[key: string]: Element | null})[ | ||
| key as string | ||
| ] ?? null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we initialize the cache property to null so that we avoid later hidden class changes and then check for null instead of undefined above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no real place to do that right? You can't do it at decorator time since it's an own property on the instance. And there's not a good initializer spot to do it before the accessor is run the first time ... 🤷 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't quite correct. The intended behavior is to always cache the first result and that the result must be either null or the found element.
Always cache the first result, but ensure it's at least null.
kevinpschaaf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Edit: Nevermind, I misunderstood what was going on here. New change makes sense. |
…update (#2095) Aligns transformer behavior to #2065 and #1980 by making the @query, @QueryAll, and @queryAssignedNodes decorator return null / [] / [] respectively before first update, instead of undefined. Also includes a fix where we were removing no-binding imports that already existed in the source. We only want to remove imports that we actually modified.
Fixes #2062. To match Lit1 behavior, the
@querydecorator returnsnull(rather thanundefined) if a decorated property is accessed before first update. Note, when thecacheoption is used, the first result is always cached and it must be eithernullor the found element. Likewise, a@queryAlldecorated property returns[]rather thanundefined.