-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Raf aligned dom updates #604
Conversation
🦋 Changeset detectedLatest commit: 9804e9f 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 |
✅ Deploy Preview for preact-signals-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Size Change: -25 B (-0.03%) Total Size: 83.3 kB
ℹ️ View Unchanged
|
5692de5
to
8e85bdf
Compare
a723274
to
3c4bd59
Compare
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.
Awesome!
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 is great! Only thought I have is if we should flag this update as "major" for the preact adapter or not. Because upgrading might break some tests.
33a3591
to
dd992d4
Compare
This all works fine, however it creates a discrepancy between browser usage and test usage which we want to avoid. The discrepancy is made clear in the failing tests. What we want to happen is for Preact to be first allowed to perform its render cycle, the effects that follow and only then should we clean up stragglers by performing the direct DOM updates. Currently what happens is that the ordering is "random" based on how the signals were registered.
Co-authored-by: Ryan Christian <[email protected]>
9d43b38
to
ed0c3fd
Compare
ed0c3fd
to
9804e9f
Compare
This also converts our synchronous DOM updates to be animation-frame aligned, this will make them execute in parallel and when the browser is prepared for it.
Let's draw out the ideal scenario we want to create:
Now we can be sure that Preact updates take presedence over our normal DOM updates.
One thing I am unsure of is the following https://github.com/preactjs/signals/blob/main/packages/preact/src/index.ts#L92-L100 whether we can reliably make this also deferred as currently it's synchronous, we could just defer the
s.data = s.peek()
part? From the tests it looks to work as we expect with RAF though 😅Fixes #315
Proof: https://codesandbox.io/p/sandbox/epic-wilbur-hhln8l
This could be considered a breaking change though 😅
Another thing to consider here would be the testing story, we could tie it into
options.debounceRendering
but that might lead to some odd behavior in terms of rendering. To align with how the user would see this behave it would need to execute Preact updates and then update the nodes directly.In the latest version of this branch the above is fixed by leveraging
options.requestAnimationFrame
which now means that any signal update needs to be wrapped inact
. In a way this was always the case as a signal update that resulted in a Preact state update would require it to be wrapped inact
but now this is the norm.Doing this investigation made me think about how we do
useSignalEffect
in React and maybe we should leverage thescheduler
package rather than injecting an arbitrary animation frame as React would better work with its own scheduler.