Skip to content

refactor: noop effect hooks on main thread#2424

Merged
HuJean merged 2 commits intomainfrom
fix/main-thread-effect-hooks-noop
Apr 7, 2026
Merged

refactor: noop effect hooks on main thread#2424
HuJean merged 2 commits intomainfrom
fix/main-thread-effect-hooks-noop

Conversation

@HuJean
Copy link
Copy Markdown
Collaborator

@HuJean HuJean commented Apr 3, 2026

Summary by CodeRabbit

  • Refactor
    • React runtime hooks (useEffect, useLayoutEffect and useImperativeHandle) now become no-ops when running in background contexts, reducing unnecessary work and improving background performance and stability.
  • Chore
    • Patch release prepared to ship the runtime behavior change and supporting internal adjustments.

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).

@HuJean HuJean requested review from Yradex and hzy as code owners April 3, 2026 10:49
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2026

🦋 Changeset detected

Latest commit: ebe224d

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

This PR includes changesets to release 2 packages
Name Type
@lynx-js/react Patch
@lynx-js/react-umd 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 Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c3231be1-f480-45c3-81a0-2167594db387

📥 Commits

Reviewing files that changed from the base of the PR and between c93abfe and f922cca.

📒 Files selected for processing (3)
  • .changeset/neat-pumas-thank.md
  • packages/react/runtime/src/hooks/react.ts
  • packages/react/runtime/src/utils.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/neat-pumas-thank.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react/runtime/src/utils.ts
  • packages/react/runtime/src/hooks/react.ts

📝 Walkthrough

Walkthrough

Added a Changeset and a shared noop utility; useEffect, useLayoutEffect, and useImperativeHandle now act as no-ops when __BACKGROUND__ is truthy, otherwise they delegate to profiling wrappers or Preact implementations as before.

Changes

Cohort / File(s) Summary
Changeset Documentation
\.changeset/neat-pumas-thank.md
New changeset added to publish a patch for @lynx-js/react recording the hooks refactor.
Hook Implementations
packages/react/runtime/src/hooks/react.ts
useEffect and useLayoutEffect now return noop when __BACKGROUND__ is truthy; useImperativeHandle is exported from this module and similarly becomes noop under __BACKGROUND__; otherwise existing profiling vs non-profiling selection remains.
Utility Exports
packages/react/runtime/src/utils.ts
Added export const noop: (...args: unknown[]) => unknown = () => {} as a shared no-op utility.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • Yradex
  • hzy

Poem

🐇 I hop through lines where functions sleep,
A tiny noop makes silence deep,
Background whispers call the tune,
Hooks rest softly by the moon,
Hooray — a gentle change for soon!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: making effect hooks (useEffect, useLayoutEffect, useImperativeHandle) into no-ops when running on the main thread, which is the primary objective reflected across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/main-thread-effect-hooks-noop

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 Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@HuJean HuJean force-pushed the fix/main-thread-effect-hooks-noop branch from 68e40d1 to c93abfe Compare April 3, 2026 10:52
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/react/runtime/src/hooks/react.ts`:
- Line 163: The ternary for useImperativeHandle is inverted: change the
expression so useImperativeHandle is a no-op on the main thread (when
__BACKGROUND__ is false) like useEffect/useLayoutEffect; specifically update the
assignment involving useImperativeHandle, usePreactUseImperativeHandle, noop and
__BACKGROUND__ so the noop branch runs when __BACKGROUND__ is false and the real
implementation (usePreactUseImperativeHandle) runs when __BACKGROUND__ is true.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2efedd07-81ae-430c-9384-6d5e4dec4e96

📥 Commits

Reviewing files that changed from the base of the PR and between 7782a4c and 68e40d1.

📒 Files selected for processing (3)
  • .changeset/neat-pumas-thank.md
  • packages/react/runtime/src/hooks/react.ts
  • packages/react/runtime/src/utils.ts

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 3, 2026

Merging this PR will degrade performance by 14.74%

❌ 1 regressed benchmark
✅ 71 untouched benchmarks
⏩ 21 skipped benchmarks1

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

Performance Changes

Benchmark BASE HEAD Efficiency
transform 1000 view elements 40.3 ms 47.3 ms -14.74%

Comparing fix/main-thread-effect-hooks-noop (ebe224d) with main (8c0e483)

Open in CodSpeed

Footnotes

  1. 21 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 Apr 3, 2026

React MTF Example

#233 Bundle Size — 206.05KiB (-0.59%).

ebe224d(current) vs c97d61a main#232(baseline)

Bundle metrics  Change 2 changes
                 Current
#233
     Baseline
#232
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 46.33% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 173 173
No change  Duplicate Modules 67 67
Change  Duplicate Code 45.78%(-0.02%) 45.79%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#233
     Baseline
#232
No change  IMG 111.23KiB 111.23KiB
Improvement  Other 94.81KiB (-1.26%) 96.03KiB

Bundle analysis reportBranch fix/main-thread-effect-hooks-noo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 3, 2026

Web Explorer

#8675 Bundle Size — 728.84KiB (0%).

ebe224d(current) vs c97d61a main#8674(baseline)

Bundle metrics  Change 1 change
                 Current
#8675
     Baseline
#8674
No change  Initial JS 43.31KiB 43.31KiB
No change  Initial CSS 2.16KiB 2.16KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 10 10
Change  Modules 148(-0.67%) 149
No change  Duplicate Modules 11 11
No change  Duplicate Code 34.69% 34.69%
No change  Packages 3 3
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8675
     Baseline
#8674
No change  Other 384.62KiB 384.62KiB
No change  JS 342.07KiB 342.07KiB
No change  CSS 2.16KiB 2.16KiB

Bundle analysis reportBranch fix/main-thread-effect-hooks-noo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 3, 2026

React External

#219 Bundle Size — 590.71KiB (-0.13%).

ebe224d(current) vs c97d61a main#218(baseline)

Bundle metrics  Change 1 change
                 Current
#219
     Baseline
#218
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 31.04% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#219
     Baseline
#218
Improvement  Other 590.71KiB (-0.13%) 591.5KiB

Bundle analysis reportBranch fix/main-thread-effect-hooks-noo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci bot commented Apr 3, 2026

React Example

#7100 Bundle Size — 236.85KiB (-0.35%).

ebe224d(current) vs c97d61a main#7099(baseline)

Bundle metrics  Change 2 changes
                 Current
#7100
     Baseline
#7099
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 38.67% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 179 179
No change  Duplicate Modules 70 70
Change  Duplicate Code 46.11%(-0.02%) 46.12%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#7100
     Baseline
#7099
No change  IMG 145.76KiB 145.76KiB
Improvement  Other 91.09KiB (-0.9%) 91.92KiB

Bundle analysis reportBranch fix/main-thread-effect-hooks-noo...Project dashboard


Generated by RelativeCIDocumentationReport issue

@HuJean HuJean force-pushed the fix/main-thread-effect-hooks-noop branch from c93abfe to f922cca Compare April 3, 2026 11:18
@HuJean HuJean merged commit 82046f4 into main Apr 7, 2026
102 of 107 checks passed
@HuJean HuJean deleted the fix/main-thread-effect-hooks-noop branch April 7, 2026 06:55
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.

3 participants