fix(react/runtime): Accelerate the timing of effect and ref triggering#652
fix(react/runtime): Accelerate the timing of effect and ref triggering#652Yradex merged 9 commits intolynx-family:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 67de64e 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 |
❌ 1 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Bundle ReportChanges will increase total bundle size by 3.05kB (0.48%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: @lynx-js/example-react-lynx-cjsAssets Changed:
|
CodSpeed Performance ReportMerging #652 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Pull Request Overview
This pull request aims to accelerate the timing of effect and ref triggering in the React runtime by removing and refactoring parts of the ref update logic and related lifecycle event calls. Key changes include:
- Removing calls to commitMainThreadPatchUpdate in list.ts and updateMainThread.
- Removing and updating ref‐related constants and ref patch handling in lifecycle and snapshot modules.
- Replacing useLayoutEffect with useEffect in hooks to adjust timing.
Reviewed Changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react/runtime/src/list.ts | Removed calls to commitMainThreadPatchUpdate to accelerate lifecycle updates. |
| packages/react/runtime/src/lifecycleConstant.ts | Removed the ref constant to reflect updated ref handling. |
| packages/react/runtime/src/lifecycle/ref/delay.ts | Added a new mechanism for handling delayed UI operations with signals. |
| packages/react/runtime/src/lifecycle/patch/updateMainThread.ts | Updated patch update logic by removing legacy ref patch updating. |
| packages/react/runtime/src/hooks/react.ts | Replaced useLayoutEffect with useEffect to improve effect timing. |
| Various test files | Updated snapshots and test expectations to align with the changes in ref patch handling. |
Comments suppressed due to low confidence (3)
packages/react/runtime/src/list.ts:320
- Confirm that removing the call to commitMainThreadPatchUpdate does not inadvertently delay or skip necessary lifecycle event propagation, especially regarding ref triggering.
commitMainThreadPatchUpdate(undefined);
packages/react/runtime/src/lifecycleConstant.ts:7
- Ensure that the removal of the 'ref' constant is intentional and that any downstream logic relying on this constant has been appropriately updated.
public static readonly ref = 'rLynxRef';
packages/react/runtime/src/hooks/react.ts:32
- Confirm that substituting useLayoutEffect with useEffect does not introduce unintended side effects in components that depend on synchronous layout updates.
return usePreactEffect(effect, deps);
c1214d0 to
605a3a6
Compare
9d3305b to
381e2a3
Compare
There is no need to detect if the type paramenter of `Parameters<>` is function. ```diff - args: Parameters<NodesRef[K] extends (...args: any[]) => any ? NodesRef[K] : never>, + args: Parameters<NodesRef[K]>, ```
Add name for tuple.
```diff
-function applyRef(ref: Ref, value: null | [number, number]): void {
+function applyRef(ref: Ref, value: null | [snapshotInstanceId: number, expIndex: number]): void {
```
Signed-off-by: Yradex <11014207+Yradex@users.noreply.github.com>
381e2a3 to
e5ca8fa
Compare
Summary
This PR fixes #405 by refactoring the ref and effect system to use Preact's ref implementation and accelerating the timing:
refanduseEffect()side effects are now guaranteed to execute before event triggers.Breaking Changes:
refanduseEffect()side effects has been moved forward. These effects will now execute before hydration is complete, rather than waiting for the main thread update to complete.<list />,refcallbacks will now be triggered during background thread rendering, regardless of component visibility. If your code depends on component visibility timing, usemain-thread:refinstead of regularref.Checklist