Skip to content

feat: add Minify.mainThreadOptions and Minify.backgroundOptions#2336

Merged
HuJean merged 2 commits intomainfrom
p/minify
Mar 24, 2026
Merged

feat: add Minify.mainThreadOptions and Minify.backgroundOptions#2336
HuJean merged 2 commits intomainfrom
p/minify

Conversation

@HuJean
Copy link
Copy Markdown
Collaborator

@HuJean HuJean commented Mar 14, 2026

Summary by CodeRabbit

  • New Features
    • Thread-specific minification: configure separate minifier options for main-thread and background-thread bundles.
    • Bundle-size optimization: new optimizeBundleSize option (boolean or per-thread) to mark thread-specific calls as pure and reduce bundle size.
  • Tests
    • Added unit and integration tests validating thread-specific minification and optimizeBundleSize behavior.
  • Chores
    • Added release notes entries and updated package compatibility range.

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 14, 2026

🦋 Changeset detected

Latest commit: 260c2e6

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

This PR includes changesets to release 5 packages
Name Type
@lynx-js/react-rsbuild-plugin Minor
@lynx-js/rspeedy Minor
create-rspeedy Minor
upgrade-rspeedy Minor
@lynx-js/react-alias-rsbuild-plugin Minor

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 Mar 14, 2026

📝 Walkthrough

Walkthrough

Adds thread-specific JS minification options (mainThreadOptions, backgroundOptions) and wires them into the bundler to produce separate SWC minimizers per thread; introduces plugin-react optimizeBundleSize which emits per-thread minify options; includes API docs, config changes, plugin logic, validation/type tests, fixtures, and integration tests.

Changes

Cohort / File(s) Summary
Changesets & API docs
\.changeset/tiny-ants-float.md, \.changeset/react-rsbuild-plugin-optimize-bundle-size.md, packages/rspeedy/core/etc/rspeedy.api.md, packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md
Added changeset entries and API doc updates announcing new Minify fields (mainThreadOptions, backgroundOptions) and PluginReactLynxOptions.optimizeBundleSize.
Config shape
packages/rspeedy/core/src/config/output/minify.ts
Expanded exported Minify interface with optional mainThreadOptions and backgroundOptions typed as Rspack.SwcJsMinimizerRspackPluginOptions.
Minify plugin logic
packages/rspeedy/core/src/plugins/minify.plugin.ts
Added mergeJsOptions() and thread-pattern constants; modify bundler chain to exclude thread-specific bundles from default minimizer and register js-main-thread and js-background SWC minimizers using merged options; introduced frozen default JS options.
Type & validation tests
packages/rspeedy/core/test/config/minify.test-d.ts, packages/rspeedy/core/test/config/validate.test.ts
Added type-level test for mainThreadOptions/backgroundOptions and expanded validation cases (valid and invalid shapes).
Plugin & integration tests
packages/rspeedy/core/test/plugins/minify.plugin.test.ts, packages/rspeedy/plugin-react/test/config.test.ts, packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts
Added tests asserting thread-specific minimizer configuration and end-to-end builds verifying per-thread pure-func removal and optimizeBundleSize behaviors; snapshots and output-content assertions added.
Fixture
packages/rspeedy/plugin-react/test/fixtures/pure-funcs/basic.js
New fixture exercising NativeModules.call, lynx.registerDataProcessors, console logs, and exported sentinel for integration tests.
Plugin React wiring
packages/rspeedy/plugin-react/src/optimizeBundleSize.ts, packages/rspeedy/plugin-react/src/pluginReactLynx.ts
Added applyOptimizeBundleSize which injects per-thread output.minify entries based on optimizeBundleSize; added optimizeBundleSize to plugin options and defaults.
Package peer deps
packages/rspeedy/plugin-config/package.json
Extended @lynx-js/rspeedy peerDependency range to include ^0.14.0.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • colinaaa
  • luhc228

Poem

🐇 Tiny paws tap on keys so bright,
Threads split left and threads split right,
Main and background learn their roles,
Options merge and tidy shoals,
Minified bundles — a rabbit's delight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature addition—two new optional configuration properties added to the Minify interface for thread-specific minifier options.

✏️ 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 p/minify

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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 14, 2026

Merging this PR will improve performance by 17.45%

⚡ 3 improved benchmarks
✅ 69 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
transform 1000 view elements 47.3 ms 40.3 ms +17.45%
basic-performance-nest-level-100 7.4 ms 6.9 ms +7.55%
basic-performance-div-100 7.3 ms 6.8 ms +7.98%

Comparing p/minify (260c2e6) with main (4157823)

Open in CodSpeed

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 Mar 14, 2026

Web Explorer

#8324 Bundle Size — 385.21KiB (0%).

260c2e6(current) vs 503ac8f main#8321(baseline)

Bundle metrics  no changes
                 Current
#8324
     Baseline
#8321
No change  Initial JS 155.59KiB 155.59KiB
No change  Initial CSS 35.1KiB 35.1KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 8 8
No change  Modules 237 237
No change  Duplicate Modules 16 16
No change  Duplicate Code 2.97% 2.97%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8324
     Baseline
#8321
No change  JS 254.26KiB 254.26KiB
No change  Other 95.85KiB 95.85KiB
No change  CSS 35.1KiB 35.1KiB

Bundle analysis reportBranch p/minifyProject dashboard


Generated by RelativeCIDocumentationReport issue

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 93.27731% with 8 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/rspeedy/core/src/plugins/minify.plugin.ts 91.56% 7 Missing ⚠️
...ges/rspeedy/plugin-react/src/optimizeBundleSize.ts 96.87% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@HuJean HuJean marked this pull request as ready for review March 23, 2026 06:00
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/rspeedy/core/src/plugins/minify.plugin.ts`:
- Around line 163-190: The current logic for mainThreadOptions.include and
backgroundOptions.include merges any inherited/user include with thread
patterns, widening scope; change this so the thread minimizers only target
thread bundles by setting mainThreadOptions.include = MAIN_THREAD_JS_PATTERN (or
[MAIN_THREAD_JS_PATTERN]) and backgroundOptions.include = BACKGROUND_JS_PATTERN
(or [BACKGROUND_JS_PATTERN]) instead of concatenating with existing include from
mergeJsOptions; update the blocks where mainThreadOptions and backgroundOptions
are set (refer to mergeJsOptions, mainThreadOptions.include,
backgroundOptions.include and the minimizer registrations
chain.optimization.minimizer('js-main-thread')/.minimizer('js-background') ) to
drop inherited include merging and use the thread pattern only.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e2cd9ec4-da75-4a95-8479-1abb40f55bf9

📥 Commits

Reviewing files that changed from the base of the PR and between e119fa3 and 7436d06.

⛔ Files ignored due to path filters (1)
  • packages/rspeedy/core/test/plugins/__snapshots__/minify.plugin.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (9)
  • .changeset/tiny-ants-float.md
  • packages/rspeedy/core/etc/rspeedy.api.md
  • packages/rspeedy/core/src/config/output/minify.ts
  • packages/rspeedy/core/src/plugins/minify.plugin.ts
  • packages/rspeedy/core/test/config/minify.test-d.ts
  • packages/rspeedy/core/test/config/validate.test.ts
  • packages/rspeedy/core/test/plugins/minify.plugin.test.ts
  • packages/rspeedy/plugin-react/test/config.test.ts
  • packages/rspeedy/plugin-react/test/fixtures/pure-funcs/basic.js

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.

🧹 Nitpick comments (2)
packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts (2)

132-179: Missing snapshot assertion for consistency.

Unlike "basic usage" and "optimize background code" tests which call expect(config?.optimization?.minimizer).toMatchSnapshot(), this test skips the snapshot assertion after initConfigs(). For consistency and to verify the minimizer configuration, consider adding the snapshot check.

♻️ Suggested fix
       ],
     })

+    const [config] = await rsbuild.initConfigs()
+    expect(config?.optimization?.minimizer).toMatchSnapshot()
+
     const { mainThreadCode, backgroundCode } = await getCode(rsbuild)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts` around lines
132 - 179, Add the same snapshot assertion used in the other tests to verify the
minimizer config: after creating rsbuild (or after calling initConfigs() if that
returns the config) capture the build config and call
expect(config?.optimization?.minimizer).toMatchSnapshot(); locate the "optimize
main-thread code" test and add this single-line assertion (referencing
config?.optimization?.minimizer) before proceeding to getCode(rsbuild) to keep
behavior consistent with the "basic usage" and "optimize background code" tests.

40-79: Consider restoring stubbed environment after test.

vi.stubEnv('NODE_ENV', 'production') modifies the environment but isn't explicitly restored. While vitest may handle cleanup between tests, explicitly using vi.unstubAllEnvs() in an afterEach or using vi.stubEnv within a scoped context would be more robust and prevent potential test pollution.

♻️ Suggested improvement

Add cleanup at the describe level:

import { afterEach, describe, expect, test, vi } from 'vitest'

describe('optimizeBundleSize', () => {
  afterEach(() => {
    vi.unstubAllEnvs()
  })
  // ... tests
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts` around lines
40 - 79, The test stubs NODE_ENV via vi.stubEnv('NODE_ENV', 'production') but
never restores it; add a teardown to call vi.unstubAllEnvs() (or
vi.unstubEnv('NODE_ENV')) in an afterEach/afterAll for this test suite (e.g.,
inside the describe that wraps the optimizeBundleSize tests) so that vi.stubEnv
is undone after each test and prevents environment leakage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts`:
- Around line 132-179: Add the same snapshot assertion used in the other tests
to verify the minimizer config: after creating rsbuild (or after calling
initConfigs() if that returns the config) capture the build config and call
expect(config?.optimization?.minimizer).toMatchSnapshot(); locate the "optimize
main-thread code" test and add this single-line assertion (referencing
config?.optimization?.minimizer) before proceeding to getCode(rsbuild) to keep
behavior consistent with the "basic usage" and "optimize background code" tests.
- Around line 40-79: The test stubs NODE_ENV via vi.stubEnv('NODE_ENV',
'production') but never restores it; add a teardown to call vi.unstubAllEnvs()
(or vi.unstubEnv('NODE_ENV')) in an afterEach/afterAll for this test suite
(e.g., inside the describe that wraps the optimizeBundleSize tests) so that
vi.stubEnv is undone after each test and prevents environment leakage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dcf584ba-f97b-487d-882e-59ca5ffd9442

📥 Commits

Reviewing files that changed from the base of the PR and between 7436d06 and b10ce03.

⛔ Files ignored due to path filters (1)
  • packages/rspeedy/plugin-react/test/__snapshots__/optimizeBundleSize.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • .changeset/react-rsbuild-plugin-optimize-bundle-size.md
  • packages/rspeedy/plugin-react/src/optimizeBundleSize.ts
  • packages/rspeedy/plugin-react/src/pluginReactLynx.ts
  • packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/react-rsbuild-plugin-optimize-bundle-size.md

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: 2

🤖 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/rspeedy/plugin-react/test/optimizeBundleSize.test.ts`:
- Line 222: This test calls getCode(rsbuild) but omits the snapshot assertion
present in tests 1–2; add a snapshot check that captures the merged minimizer
configuration (extract from mainThreadCode and/or backgroundCode returned by
getCode) so regressions are detected — mirror the pattern used in the earlier
tests by asserting the minimizer config (or the full
mainThreadCode/backgroundCode string if those tests do) with
expect(...).toMatchSnapshot().
- Line 168: The test calls getCode(rsbuild) to extract mainThreadCode and
backgroundCode but omits the snapshot assertion used in other tests; add an
assertion like expect(config?.optimization?.minimizer).toMatchSnapshot()
(matching the pattern used in Tests 1 and 2) after obtaining the build output so
the minimizer configuration is captured consistently—look for the
getCode(rsbuild) call and add the snapshot assertion referencing
config?.optimization?.minimizer to the same test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6776a15-8b3e-43d3-aa51-34633089e9c1

📥 Commits

Reviewing files that changed from the base of the PR and between b10ce03 and d472b0d.

⛔ Files ignored due to path filters (1)
  • packages/rspeedy/plugin-react/test/__snapshots__/optimizeBundleSize.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • .changeset/react-rsbuild-plugin-optimize-bundle-size.md
  • packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md
  • packages/rspeedy/plugin-react/src/optimizeBundleSize.ts
  • packages/rspeedy/plugin-react/src/pluginReactLynx.ts
  • packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/react-rsbuild-plugin-optimize-bundle-size.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/rspeedy/plugin-react/src/pluginReactLynx.ts
  • packages/rspeedy/plugin-react/src/optimizeBundleSize.ts

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

♻️ Duplicate comments (1)
packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts (1)

132-179: ⚠️ Potential issue | 🟡 Minor

Add minimizer snapshot assertions in the last two tests for consistency.

Line 168 and Line 222 run builds but don’t snapshot config?.optimization?.minimizer, unlike earlier cases. This reduces regression visibility for config merge behavior.

📸 Proposed consistency update
   test('optimize main-thread code', async () => {
@@
     const rsbuild = await createRspeedy({
@@
     })
 
+    const [config] = await rsbuild.initConfigs()
+    expect(config?.optimization?.minimizer).toMatchSnapshot()
+
     const { mainThreadCode, backgroundCode } = await getCode(rsbuild)
@@
   test('merge backgroundOptions and mainThreadOptions', async () => {
@@
     const rsbuild = await createRspeedy({
@@
     })
 
+    const [config] = await rsbuild.initConfigs()
+    expect(config?.optimization?.minimizer).toMatchSnapshot()
+
     const { mainThreadCode, backgroundCode } = await getCode(rsbuild)

Also applies to: 181-232

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts` around lines
132 - 179, Add snapshot assertions for the merged minimizer config in the two
tests that currently run builds but don’t assert it (including the test titled
"optimize main-thread code"); after creating the rsbuild (from createRspeedy)
and/or after getCode, capture rsbuild.config?.optimization?.minimizer and add an
expectation to matchSnapshot so the merged minimizer options are snapshotted
(reference createRspeedy, pluginReactLynx, and getCode to locate where to insert
the expect for config?.optimization?.minimizer).
🧹 Nitpick comments (2)
packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts (2)

14-18: Preserve build error details in the failure path.

getCode currently drops the original exception, which makes CI failures harder to debug.

🛠️ Proposed tweak
 async function getCode(rsbuild: RspeedyInstance) {
   try {
     await rsbuild.build()
-  } catch (_error) {
-    expect.fail('build should succeed')
+  } catch (error) {
+    expect.fail(
+      `build should succeed: ${
+        error instanceof Error ? (error.stack ?? error.message) : String(error)
+      }`,
+    )
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts` around lines
14 - 18, The test currently swallows the original build exception in the catch
for awaiting rsbuild.build() (and getCode appears to drop exceptions elsewhere);
modify the catch to preserve and surface the error details by using the caught
error (rename _error to error) and include error.message and/or error.stack in
the expect.fail call (or rethrow the error) so the full failure details from
rsbuild.build() (and from getCode) are available in CI logs.

47-48: Use fileURLToPath instead of .pathname for fixture paths.

Using new URL(...).pathname can produce incorrect OS-specific paths (notably Windows and encoded characters). Prefer fileURLToPath.

🌐 Proposed cross-platform fix
 import { existsSync, readFileSync } from 'node:fs'
 import path from 'node:path'
+import { fileURLToPath } from 'node:url'
@@
-            main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
-              .pathname,
+            main: fileURLToPath(
+              new URL('./fixtures/pure-funcs/basic.js', import.meta.url),
+            ),
@@
-            main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
-              .pathname,
+            main: fileURLToPath(
+              new URL('./fixtures/pure-funcs/basic.js', import.meta.url),
+            ),
@@
-            main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
-              .pathname,
+            main: fileURLToPath(
+              new URL('./fixtures/pure-funcs/basic.js', import.meta.url),
+            ),
@@
-            main: new URL('./fixtures/pure-funcs/basic.js', import.meta.url)
-              .pathname,
+            main: fileURLToPath(
+              new URL('./fixtures/pure-funcs/basic.js', import.meta.url),
+            ),

Also applies to: 89-90, 140-141, 189-190

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts` around lines
47 - 48, Replace uses of new URL(...).pathname with fileURLToPath(new URL(...))
to ensure correct cross-platform fixture paths; import fileURLToPath from
'node:url' and update each occurrence (the object properties named "main" where
fixtures are referenced in optimizeBundleSize.test.ts, e.g., the new
URL('./fixtures/pure-funcs/basic.js', import.meta.url).pathname instances and
the other two similar occurrences mentioned) so tests use fileURLToPath(new
URL(...)) instead of .pathname.
🤖 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/rspeedy/plugin-react/test/optimizeBundleSize.test.ts`:
- Line 7: Tests in optimizeBundleSize.test.ts call vi.stubEnv('NODE_ENV',
'production') in multiple tests but never restore the environment, causing state
leakage; add an afterEach hook to call vi.unstubAllEnvs() (and import afterEach
from 'vitest' if not already) so each test resets stubbed env vars, e.g. add
afterEach(() => vi.unstubAllEnvs()) alongside existing imports and tests to
ensure clean state between tests that use vi.stubEnv.

---

Duplicate comments:
In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts`:
- Around line 132-179: Add snapshot assertions for the merged minimizer config
in the two tests that currently run builds but don’t assert it (including the
test titled "optimize main-thread code"); after creating the rsbuild (from
createRspeedy) and/or after getCode, capture
rsbuild.config?.optimization?.minimizer and add an expectation to matchSnapshot
so the merged minimizer options are snapshotted (reference createRspeedy,
pluginReactLynx, and getCode to locate where to insert the expect for
config?.optimization?.minimizer).

---

Nitpick comments:
In `@packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts`:
- Around line 14-18: The test currently swallows the original build exception in
the catch for awaiting rsbuild.build() (and getCode appears to drop exceptions
elsewhere); modify the catch to preserve and surface the error details by using
the caught error (rename _error to error) and include error.message and/or
error.stack in the expect.fail call (or rethrow the error) so the full failure
details from rsbuild.build() (and from getCode) are available in CI logs.
- Around line 47-48: Replace uses of new URL(...).pathname with
fileURLToPath(new URL(...)) to ensure correct cross-platform fixture paths;
import fileURLToPath from 'node:url' and update each occurrence (the object
properties named "main" where fixtures are referenced in
optimizeBundleSize.test.ts, e.g., the new URL('./fixtures/pure-funcs/basic.js',
import.meta.url).pathname instances and the other two similar occurrences
mentioned) so tests use fileURLToPath(new URL(...)) instead of .pathname.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d7544d4e-f6bb-4d0c-afc7-60d5e98d7d21

📥 Commits

Reviewing files that changed from the base of the PR and between d472b0d and 260c2e6.

⛔ Files ignored due to path filters (1)
  • packages/rspeedy/plugin-react/test/__snapshots__/optimizeBundleSize.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • .changeset/react-rsbuild-plugin-optimize-bundle-size.md
  • packages/rspeedy/plugin-config/package.json
  • packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md
  • packages/rspeedy/plugin-react/src/optimizeBundleSize.ts
  • packages/rspeedy/plugin-react/src/pluginReactLynx.ts
  • packages/rspeedy/plugin-react/test/optimizeBundleSize.test.ts
✅ Files skipped from review due to trivial changes (3)
  • .changeset/react-rsbuild-plugin-optimize-bundle-size.md
  • packages/rspeedy/plugin-config/package.json
  • packages/rspeedy/plugin-react/src/pluginReactLynx.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md
  • packages/rspeedy/plugin-react/src/optimizeBundleSize.ts

@upupming
Copy link
Copy Markdown
Collaborator

LGTM, but small questions

@HuJean HuJean enabled auto-merge (squash) March 24, 2026 04:47
@HuJean HuJean merged commit e3e63de into main Mar 24, 2026
82 of 84 checks passed
@HuJean HuJean deleted the p/minify branch March 24, 2026 04:49
colinaaa pushed a commit that referenced this pull request Apr 6, 2026
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/rspeedy@0.14.0

### Minor Changes

- feat: add `Minify.mainThreadOptions` and `Minify.backgroundOptions`
for thread-specific minifier.
([#2336](#2336))

### Patch Changes

- Bump Rsbuild v1.7.4 with Rspack v1.7.10.
([#2384](#2384))

-   Updated dependencies \[]:
    -   @lynx-js/web-rsbuild-server-middleware@0.20.0

## @lynx-js/lynx-bundle-rslib-config@0.3.0

### Minor Changes

- **BREAKING CHANGE**:
([#2370](#2370))

Simplify the API for external bundle builds by `externalsPresets` and
`externalsPresetDefinitions`.

### Patch Changes

- Preserve the default external-bundle `output.minify.jsOptions` when
users set `output.minify: true` in `defineExternalBundleRslibConfig`, so
required minifier options are not lost.
([#2390](#2390))

## @lynx-js/external-bundle-rsbuild-plugin@0.1.0

### Minor Changes

- **BREAKING CHANGE**:
([#2370](#2370))

Simplify the API for external bundle builds by `externalsPresets` and
`externalsPresetDefinitions`.

### Patch Changes

- Updated dependencies
\[[`7b7a0c6`](7b7a0c6)]:
    -   @lynx-js/externals-loading-webpack-plugin@0.1.0

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

### Minor Changes

- feat: support `optimizeBundleSize` option to remove unused code for
main-thread and background.
([#2336](#2336))

- If `optimizeBundleSize` is `true` or `optimizeBundleSize.background`
is `true`, `lynx.registerDataProcessors` calls will be marked as pure
for the background thread output.
- If `optimizeBundleSize` is `true` or `optimizeBundleSize.mainThread`
is `true`, `NativeModules.call` and `lynx.getJSModule` calls will be
marked as pure for the main-thread output.

### Patch Changes

- refactor: remove `modifyWebpackChain` since Rsbuild 2.0 dropped
webpack support
([#2397](#2397))

- Updated dependencies
\[[`9193711`](9193711)]:
    -   @lynx-js/template-webpack-plugin@0.10.7
    -   @lynx-js/css-extract-webpack-plugin@0.7.0
    -   @lynx-js/react-webpack-plugin@0.8.0
    -   @lynx-js/react-alias-rsbuild-plugin@0.14.0
    -   @lynx-js/use-sync-external-store@1.5.0
    -   @lynx-js/react-refresh-webpack-plugin@0.3.5

## @lynx-js/web-core@0.20.0

### Minor Changes

- **This is a breaking change**
([#2322](#2322))

    ## Architectural Upgrade: `web-core-wasm` replaces `web-core`

This release marks a major architectural upgrade for the web platform.
The experimental, WASM-powered engine formerly known as `web-core-wasm`
has been fully stabilized and merged into the main branch, completely
replacing the previous pure JS/TS based `web-core` implementation. This
consolidation massively improves execution performance and aligns the
API boundaries of the Web platform directly with other native Lynx
implementations.

    ### 🎉 Added Features

- **Core API Enhancements**: Successfully exposed and supported
`__QuerySelector` and `__InvokeUIMethod` methods.
- **Security & CSP Compliance**: Added a `nonce` attribute to the
iframe's `srcdoc` script execution, strengthening Content Security
Policy (CSP) compliance.
    -   **`<lynx-view>` Parameter Enhancements**:
- Added the `browser-config` attribute and property to `<lynx-view>`.
Development environments can now supply a `BrowserConfig` object (e.g.,
configuring `pixelRatio`, `pixelWidth`, `pixelHeight`) allowing the
`systemInfo` payload to be dynamically configured at the instance level.

    ### 🔄 Changed Features

- **Legacy JSON Backwards Compatibility**: Delivered comprehensive fixes
and optimizations to deeply support legacy JSON output templates:
- Added support for lazy loading execution mode (`lazy usage`).
- Implemented the correct decoding and handling of `@keyframe` animation
rules.
- Rectified rule scoping matching including scoped CSS, root selectors,
and type selectors.

- **Ecosystem Migration**: Updated testing and ecosystem applications
(such as `web-explorer` and `shell-project`) to migrate away from
obsolete fragmented dependencies. The new WASM architecture seamlessly
integrates Element APIs and CSS directly inside the core client module,
requiring a much simpler initialization footprint.

        **Before (Legacy `web-core` + `web-elements`):**

        ```typescript
        // Required multiple imports to assemble the environment
        import "@lynx-js/web-core/client";
import type { LynxViewElement as LynxView } from "@lynx-js/web-core";

        // Had to manually import separate elements and their CSS
        import "@lynx-js/web-elements/index.css";
        import "@lynx-js/web-elements/all";

const lynxView = document.createElement("lynx-view") as LynxView;
        // ...
        ```

        **After (New `web-core` unified architecture):**

        ```typescript
// The new engine natively registers Web Components and injects
fundamental CSS
        import "@lynx-js/web-core/client";
import type { LynxViewElement as LynxView } from
"@lynx-js/web-core/client";

const lynxView = document.createElement("lynx-view") as LynxView;
        // ...
        ```

_(Applications can now drop `@lynx-js/web-elements` entirely from their
`package.json` dependencies)._

- **Dependency & Boot Sequence Improvements**: Re-architected module
loading pathways. Promoted `wasm-feature-detect` directly to a core
dependency, and hardened the web worker count initialization assertions.

- **Initialization Optimizations**: Converted `SERVER_IN_SHADOW_CSS`
initialization bounds to use compilation-time constant expressions for
better optimization.

    ### 🗑️ Deleted Features & Structural Deprecations

    -   **`<lynx-view>` Parameter Removals**:
- Removed the `thread-strategy` property and attribute. Historically,
this permitted consumers to toggle between `'multi-thread'` and
`'all-on-ui'` modes depending on how they wanted the background logic to
be executed. The WASM-driven architecture enforces a consolidated
concurrency model, deprecating this `<lynx-view>` attribute entirely.
- Removed the `overrideLynxTagToHTMLTagMap` property/attribute. HTML tag
overriding mechanism has been deprecated in the new engine.
- Removed the `customTemplateLoader` property handler from
`<lynx-view>`.
- Removed the `inject-head-links` property and attribute
(`injectHeadLinks`), which previously was used to automatically inject
`<link rel="stylesheet">` tags from the document head into the
`lynx-view` shadow root.
- **Fragmented Packages Removal**: The new cohesive WASM architecture
native to `@lynx-js/web-core` handles cross-thread communication, worker
boundaries, and rendering loops uniformly. Consequently, multiple
obsolete packages have been completely removed from the workspace:
        -   `@lynx-js/web-mainthread-apis`
        -   `@lynx-js/web-worker-runtime`
        -   `@lynx-js/web-core-server`
- `@lynx-js/web-core-wasm-e2e` (transitioned into standard test suites)

- Added support for `rpx` unit
([#2377](#2377))

    **This is a breaking change**

    The following Styles has been added to `web-core`

    ```css
    lynx-view {
      width: 100%;
      container-name: lynx-view;
      container-type: inline-size;
      --rpx-unit: 1cqw;
    }
    ```

    Check MDN for the details about these styles:

-
<https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/container-name>
-
<https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/container-type>
-
<https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Containment/Container_queries>

    ### how it works?

    For the following code

    ```html
    <view style="height:1rpx"></view>
    ```

    it will be transformed to

    ```html
    <view style="height:calc(1 * var(--rpx-unit))"></view>
    ```

Therefore you could use any `<length>` value to replace the unit, for
example:

    ```html
    <lynx-view style="--rpx-unit:1px"></lynx-view>
    ```

    By default, the --rpx-unit value is `1cqw`

- Added support for transform `vw` and `vh` unit
([#2377](#2377))

Add `transform-vw` and `transform-vh` attributes and properties on
`<lynx-view>`.

    For the following code

    ```html
    <view style="height:1vw"></view>
    ```

If the `transform-vw` is enabled `<lynx-view transform-vw="true">`, it
will be transformed to

    ```html
    <view style="height:calc(1 * var(--vw-unit))"></view>
    ```

Therefore you could use any `<length>` value to replace the unit, for
example:

    ```html
    <lynx-view style="--vw-unit:1px"></lynx-view>
    ```

### Patch Changes

- feat(web-core): add `is_bubble` parameter to `common_event_handler` to
properly handle non-bubbling events like `window.Event('click', {
bubbles: false })`.
([#2399](#2399))

- chore: update readme
([#2380](#2380))

- fix: the output format should be module
([#2388](#2388))

- opt: use opt-level 3 to compile wasm
([#2371](#2371))

- fix(web-core): avoid partial bundle loading and double fetching when
fetchBundle is called concurrently for the same url.
([#2386](#2386))

- fix(web-core): fallback to the original export chunk when
`processEvalResult` is absent during `queryComponent` execution
([#2399](#2399))

- fix: tokenizing inline style values correctly to support rpx and ppx
unit conversion
([#2381](#2381))

This fixes an issue where the `transform_inline_style_key_value_vec` API
bypassed the CSS tokenizer, preventing dimension units like `rpx` or
`ppx` from being successfully transformed into `calc` strings when
specified via inline styles.

- feat: add mts lynx.querySelectorAll API
([#2382](#2382))

- fix: mts in lazy component
([#2375](#2375))

- fix: enableJSDataProcessor not work
([#2372](#2372))

- feat: add `ppx` unit support for CSS, transforming to `calc(... *
var(--ppx-unit))` directly.
([#2381](#2381))

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

## @lynx-js/externals-loading-webpack-plugin@0.1.0

### Minor Changes

- **BREAKING CHANGE**:
([#2370](#2370))

Simplify the API for external bundle builds by `externalsPresets` and
`externalsPresetDefinitions`.

## @lynx-js/devtool-connector@0.1.1

### Patch Changes

- fix: align GlobalKeys with Android DevToolSettings keys and filter
global switch responses
([#2392](#2392))

## @lynx-js/devtool-mcp-server@0.5.1

### Patch Changes

- Updated dependencies
\[[`95fff27`](95fff27)]:
    -   @lynx-js/devtool-connector@0.1.1

## @lynx-js/react@0.117.1

### Patch Changes

- Update preact version to simplify `setProperty` implementation
([#2367](#2367))

## @lynx-js/react-umd@0.117.1

### Patch Changes

- Add a new `entry` export to `@lynx-js/react-umd` for reuse by wrapper
libraries of `@lynx-js/react`.
([#2370](#2370))

## create-rspeedy@0.14.0

### Patch Changes

- Add optional Lynx DevTool skill.
([#2421](#2421))

- move Vitest integration to create-rstack extraTools and merge the
Vitest templates into a single incremental overlay
([#2408](#2408))

## @lynx-js/kitten-lynx-test-infra@0.1.2

### Patch Changes

- Updated dependencies
\[[`95fff27`](95fff27)]:
    -   @lynx-js/devtool-connector@0.1.1

## @lynx-js/template-webpack-plugin@0.10.7

### Patch Changes

- use path.posix.format instead of path.format to ensure consistent path
separators across platforms
([#2359](#2359))

- Updated dependencies
\[[`75960cd`](75960cd),
[`518c310`](518c310),
[`863469e`](863469e),
[`dc18c5c`](dc18c5c),
[`7d242f3`](7d242f3),
[`62bebcf`](62bebcf),
[`75960cd`](75960cd),
[`182f568`](182f568),
[`1aa051d`](1aa051d),
[`6b46f7e`](6b46f7e),
[`fcda36a`](fcda36a),
[`182f568`](182f568),
[`138f727`](138f727),
[`138f727`](138f727)]:
    -   @lynx-js/web-core@0.20.0

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



## upgrade-rspeedy@0.14.0



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



## @lynx-js/web-worker-rpc@0.20.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.

2 participants