Skip to content

fix(react/runtime): fix runOnBackground() failure in certain cases#1878

Merged
Yradex merged 1 commit intolynx-family:mainfrom
Yradex:mts/fix-hydration
Oct 10, 2025
Merged

fix(react/runtime): fix runOnBackground() failure in certain cases#1878
Yradex merged 1 commit intolynx-family:mainfrom
Yradex:mts/fix-hydration

Conversation

@Yradex
Copy link
Copy Markdown
Collaborator

@Yradex Yradex commented Oct 10, 2025

Fixes #1875.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where main-thread functions created during initial render could not call runOnBackground() after hydration, ensuring background tasks are correctly queued and executed.
  • Tests

    • Expanded hydration and runOnBackground test coverage with clearer assertions and snapshots for first-screen vs. non-first-screen behavior.
  • Chores

    • Added a changeset for a patch release, including a patch-level update to the @lynx-js/react dependency.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@Yradex Yradex requested a review from hzy as a code owner October 10, 2025 09:57
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Oct 10, 2025

🦋 Changeset detected

Latest commit: d445fb1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lynx-js/react Patch

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 10, 2025

📝 Walkthrough

Walkthrough

Adds a changeset for a patch to @lynx-js/react and updates hydration logic to correctly handle main-thread functions created during initial render so they can call runOnBackground() post-hydration. Corresponding tests are expanded to assert hydration fields and delayed execution behavior.

Changes

Cohort / File(s) Summary
Changeset
\.changeset/kind-rocks-spend.md
Adds a patch-level changeset for @lynx-js/react documenting a fix for main-thread functions failing to call runOnBackground() after hydration.
Tests: runOnBackground hydration
packages/react/worklet-runtime/__test__/runOnBackground.test.js
Refactors expectations and formatting; adds assertions for per-function hydration fields (_isFirstScreen, _jsFnId, _execId); snapshots and access patterns updated; logic behavior unchanged.
Runtime hydration logic
packages/react/worklet-runtime/src/hydrate.ts
Formatting updates and a new branch in hydrateDelayRunOnBackgroundTasks: when no _delayIndices, update firstScreenFnObj with _isFirstScreen=false, set execId, and merge fnObj; call sites reformatted; no exported API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Suggested labels

framework:React

Suggested reviewers

  • hzy
  • colinaaa
  • gaoachao

Poem

I thump my paws—hydration’s here,
Queues aligned, our threads run clear.
First-screen whispers, background hum,
Delay or not, the calls still come.
Patch-sized hop, but tidy tracks—
A bunny’s joy in well-queued stacks. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the main change—fixing runOnBackground() failures in the React runtime—and follows conventional commit style without unnecessary detail.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@relativeci
Copy link
Copy Markdown

relativeci bot commented Oct 10, 2025

React Example

#5833 Bundle Size — 237.56KiB (0%).

d445fb1(current) vs 7e06ca9 main#5831(baseline)

Bundle metrics  no changes
                 Current
#5833
     Baseline
#5831
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 166 166
No change  Duplicate Modules 68 68
No change  Duplicate Code 46.82% 46.82%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#5833
     Baseline
#5831
No change  IMG 145.76KiB 145.76KiB
No change  Other 91.8KiB 91.8KiB

Bundle analysis reportBranch Yradex:mts/fix-hydrationProject dashboard


Generated by RelativeCIDocumentationReport issue

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Oct 10, 2025

CodSpeed Performance Report

Merging #1878 will degrade performances by 6.13%

Comparing Yradex:mts/fix-hydration (d445fb1) with main (7e06ca9)

Summary

❌ 1 regression
✅ 52 untouched
⏩ 3 skipped1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
transform 1000 view elements 42.2 ms 45 ms -6.13%

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci bot commented Oct 10, 2025

Web Explorer

#5829 Bundle Size — 364.3KiB (0%).

d445fb1(current) vs 7e06ca9 main#5827(baseline)

Bundle metrics  Change 1 change
                 Current
#5829
     Baseline
#5827
No change  Initial JS 144.52KiB 144.52KiB
No change  Initial CSS 32KiB 32KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 8 8
Change  Modules 220(+0.92%) 218
No change  Duplicate Modules 16 16
No change  Duplicate Code 3.23% 3.23%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#5829
     Baseline
#5827
No change  JS 238.5KiB 238.5KiB
No change  Other 93.8KiB 93.8KiB
No change  CSS 32KiB 32KiB

Bundle analysis reportBranch Yradex:mts/fix-hydrationProject dashboard


Generated by RelativeCIDocumentationReport issue

@Yradex Yradex merged commit 2da147d into lynx-family:main Oct 10, 2025
51 of 52 checks passed
@Yradex Yradex deleted the mts/fix-hydration branch October 10, 2025 11:32
colinaaa pushed a commit that referenced this pull request Oct 12, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @lynx-js/web-core@0.18.0

### Minor Changes

-   fix: ([#1837](#1837))

    1.  `LynxView.updateData()` cannot trigger `dataProcessor`.

2. **This is a break change:** The second parameter of
`LynxView.updateData()` has been changed from `UpdateDataType` to
`string`, which is the `processorName` (default is `default` which will
use `defaultDataProcessor`). This change is to better align with Native.
The current complete type is as follows:

    ```ts
LynxView.updateData(data: Cloneable, processorName?: string | undefined,
callback?: (() => void) | undefined): void
    ```

### Patch Changes

- Updated dependencies
\[[`77397fd`](77397fd),
[`7d90ed5`](7d90ed5)]:
    -   @lynx-js/web-worker-runtime@0.18.0
    -   @lynx-js/web-constants@0.18.0
    -   @lynx-js/web-mainthread-apis@0.18.0
    -   @lynx-js/web-worker-rpc@0.18.0

## @lynx-js/react@0.114.2

### Patch Changes

- fix: main thread functions created during the initial render cannot
correctly call `runOnBackground()` after hydration
([#1878](#1878))

## @lynx-js/rspeedy@0.11.6

### Patch Changes

- Should apply `dev.hmr` and `dev.liveReload` to Rsbuild config.
([#1882](#1882))

- Support CLI flag `--root` to specify the root of the project.
([#1836](#1836))

## @lynx-js/react-rsbuild-plugin@0.11.2

### Patch Changes

- Fix using wrong version of `@lynx-js/react/refresh`.
([#1756](#1756))

-   Updated dependencies \[]:
    -   @lynx-js/react-alias-rsbuild-plugin@0.11.2
    -   @lynx-js/use-sync-external-store@1.5.0
    -   @lynx-js/react-refresh-webpack-plugin@0.3.4
    -   @lynx-js/react-webpack-plugin@0.7.1

## @lynx-js/web-constants@0.18.0

### Patch Changes

-   fix: ([#1837](#1837))

    1.  `LynxView.updateData()` cannot trigger `dataProcessor`.

2. **This is a break change:** The second parameter of
`LynxView.updateData()` has been changed from `UpdateDataType` to
`string`, which is the `processorName` (default is `default` which will
use `defaultDataProcessor`). This change is to better align with Native.
The current complete type is as follows:

    ```ts
LynxView.updateData(data: Cloneable, processorName?: string | undefined,
callback?: (() => void) | undefined): void
    ```

-   Updated dependencies \[]:
    -   @lynx-js/web-worker-rpc@0.18.0

## @lynx-js/web-elements@0.8.8

### Patch Changes

-   fix: ([#1837](#1837))

    1.  `LynxView.updateData()` cannot trigger `dataProcessor`.

2. **This is a break change:** The second parameter of
`LynxView.updateData()` has been changed from `UpdateDataType` to
`string`, which is the `processorName` (default is `default` which will
use `defaultDataProcessor`). This change is to better align with Native.
The current complete type is as follows:

    ```ts
LynxView.updateData(data: Cloneable, processorName?: string | undefined,
callback?: (() => void) | undefined): void
    ```

-   Updated dependencies \[]:
    -   @lynx-js/web-elements-template@0.8.8

## @lynx-js/web-explorer@0.0.10

### Patch Changes

- chore: update `@lynx-js/lynx-core` to `0.1.3`, `@lynx-js/web-core` to
`0.17.1`. ([#1839](#1839))

## @lynx-js/web-mainthread-apis@0.18.0

### Patch Changes

-   fix: ([#1837](#1837))

    1.  `LynxView.updateData()` cannot trigger `dataProcessor`.

2. **This is a break change:** The second parameter of
`LynxView.updateData()` has been changed from `UpdateDataType` to
`string`, which is the `processorName` (default is `default` which will
use `defaultDataProcessor`). This change is to better align with Native.
The current complete type is as follows:

    ```ts
LynxView.updateData(data: Cloneable, processorName?: string | undefined,
callback?: (() => void) | undefined): void
    ```

- feat: mouse event output structures remain aligned
([#1820](#1820))

- Updated dependencies
\[[`77397fd`](77397fd)]:
    -   @lynx-js/web-constants@0.18.0
    -   @lynx-js/web-style-transformer@0.18.0

## @lynx-js/web-worker-runtime@0.18.0

### Patch Changes

-   fix: ([#1837](#1837))

    1.  `LynxView.updateData()` cannot trigger `dataProcessor`.

2. **This is a break change:** The second parameter of
`LynxView.updateData()` has been changed from `UpdateDataType` to
`string`, which is the `processorName` (default is `default` which will
use `defaultDataProcessor`). This change is to better align with Native.
The current complete type is as follows:

    ```ts
LynxView.updateData(data: Cloneable, processorName?: string | undefined,
callback?: (() => void) | undefined): void
    ```

- Updated dependencies
\[[`77397fd`](77397fd),
[`7d90ed5`](7d90ed5)]:
    -   @lynx-js/web-constants@0.18.0
    -   @lynx-js/web-mainthread-apis@0.18.0
    -   @lynx-js/web-worker-rpc@0.18.0

## create-rspeedy@0.11.6



## @lynx-js/react-alias-rsbuild-plugin@0.11.2



## upgrade-rspeedy@0.11.6



## @lynx-js/web-core-server@0.18.0



## @lynx-js/web-elements-template@0.8.8



## @lynx-js/web-rsbuild-server-middleware@0.18.0



## @lynx-js/web-style-transformer@0.18.0



## @lynx-js/web-worker-rpc@0.18.0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: runOnBackground() failure in certain cases

2 participants