-
Notifications
You must be signed in to change notification settings - Fork 1k
[labs/task] Run tasks in update instead of updated #4004
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
🦋 Changeset detectedLatest commit: b359737 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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
|
|
This is a difficult choice. Updated we can be pretty sure all computed properties should be synced by then. Also we know DOM will always be ready in the task. Can you spin up an example real quick with a task that accesses a @query and see how it looks DX-wise? An example can maybe be a list of items with a [selected] attribute or something like select and option but you don't hook the value into the Lit data system |
|
@e111077 yeah, I can add that as a test. A task will not be able to see rendered updates though. I think we need to find a case where something doesn't work at all, not just that we get a double-render, and let that guide us. If someone wanted to trigger a task based on updated shadow root contents... is that a supported case? I thought we kind of resolved to do this a while back, based on this comment: #1499 (comment) But... do we need this to be configurable? |
|
Personally don't care about a test case too much just want to investigate the DX. Like does the queried property go in the arguments list now? It won't trigger a re-render when it updates but it will trigger dirty props etc. |
|
I mean to add the test case as a reviewed, checked-in, working example of the DX, with some assertions about whether it works. I don't think this will be a good case with the new timing, so I want to get it in and have eyes on it. |
|
I added the test/example (didn't push yet) and... I don't know. It might be better to take the double-render hit on pending tasks. For many cases, and especially SSR compatibility, update timing is better. So I wonder if we should have an option, and what the default should be? Is depending on DOM common? Could tasks using updated timing skip SSR? |
|
If we keep it as so we push people towards the data system rather than accessing DOM directly which is arguably "idiomatic Lit". So someone in updated or firstUpdated can access the DOM, update a reactive property dependency in the Task props array, and then the rerender on update can catch it. The Task may run twice (perhaps noop the first time) but the element in both cases would lifecycle twice. But in the cases where state doesn't rely on DOM (a fully SSR-able component) then there is no double render. Idk drawbacks either way, but I'd argue the DOM case is not as common but not uncommon |
|
What about: autoRun?: boolean | 'afterUpdate'The default timing would be |
|
@e111077 I added a (I can't for the life of me figure out why the task tests can't see the |
|
Also wondering why not willUpdate? That would allow fetches to be completed on the server and send pure HTML to the user... Oh I guess reactive controllers don't have hostWillUpdate. I think letting the user select the lifecycle like this is a decent idea. Would be cool if we could enable server fetches though |
|
Yeah, we don't have I think we can enable server fetches - easier - with the new default timing. @kevinpschaaf had a branch that made SSR wait for async controllers, and this timing lets us know sooner that a task will have been started. |
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 pending Peter's suggestions, though I reckon the migration for users is not gonna be great. Personally not looking forward to upgrading my implementations
Fixes #4003
Fixes #1808 (there were some issues in the jsdoc example)
This is a breaking change.
This also adds
'afterUpdate'as a valid value forautoRun, which preserves the existing timing. That's useful for tasks that need to read state changes in update, such as DOM.