feat(react): shared runtime imports#1968
Conversation
🦋 Changeset detectedLatest commit: abff45c 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 |
📝 WalkthroughWalkthroughDetects imports annotated with Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧠 Learnings (8)📓 Common learnings📚 Learning: 2025-11-05T03:26:52.546ZApplied to files:
📚 Learning: 2025-09-28T08:46:43.177ZApplied to files:
📚 Learning: 2025-08-21T07:21:51.621ZApplied to files:
📚 Learning: 2025-09-10T11:42:36.855ZApplied to files:
📚 Learning: 2025-09-18T04:43:54.426ZApplied to files:
📚 Learning: 2025-08-11T05:57:18.212ZApplied to files:
📚 Learning: 2025-08-27T12:42:01.095ZApplied to files:
🧬 Code graph analysis (1)packages/react/transform/crates/swc_plugin_worklet/lib.rs (1)
🔇 Additional comments (7)
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. Comment |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
CodSpeed Performance ReportMerging #1968 will degrade performances by 5.15%Comparing Summary
Benchmarks breakdown
Footnotes
|
Web Explorer#6573 Bundle Size — 372.9KiB (0%).abff45c(current) vs f7256d5 main#6568(baseline) Bundle metrics
|
| Current #6573 |
Baseline #6568 |
|
|---|---|---|
146.32KiB |
146.32KiB |
|
32.4KiB |
32.4KiB |
|
0% |
48.3% |
|
8 |
8 |
|
8 |
8 |
|
230 |
230 |
|
16 |
16 |
|
2.97% |
2.97% |
|
4 |
4 |
|
0 |
0 |
Bundle size by type no changes
| Current #6573 |
Baseline #6568 |
|
|---|---|---|
243.52KiB |
243.52KiB |
|
96.98KiB |
96.98KiB |
|
32.4KiB |
32.4KiB |
Bundle analysis report Branch Yradex:mts/dev-2 Project dashboard
Generated by RelativeCI Documentation Report issue
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/react/transform/crates/swc_plugin_worklet/lib.rs (2)
55-63: Shared-identifiers state wiring looks correct; consider clearing per module as a guard
shared_identifiers: FxHashSet<Id>is correctly added toWorkletVisitorand initialized viaFxHashSet::default()innew, so the collector always sees a defined set.Since
visit_mut_moduleis effectively the per-file entrypoint, you might optionally clear this set at the top of that method to guard against any future reuse of the same visitor instance across multipleModules:fn visit_mut_module(&mut self, n: &mut Module) { - // First process imports to detect shared-runtime modules + // Reset per-module shared identifiers before scanning imports + self.shared_identifiers.clear(); + // First process imports to detect shared-runtime modulesNot required today (the visitor is constructed per module in tests/NAPI), but it makes the lifecycle explicit and future-proof.
Also applies to: 523-532
467-515:is_shared_runtime_importonly errors on string values; consider also flagging non-string runtime valuesThe helper correctly detects both identifier and string-literal keys named
runtimeand:
- Treats
runtime: "shared"and"runtime": "shared"as shared-runtime imports.- Emits a clear error for other string values.
Right now, if someone writes something like:
import { foo } from './shared.js' with { runtime: 123 }; // or import { foo } from './shared.js' with { runtime: someExpr };
is_shared_runtime_importwill silently treat this as a non-shared import and will not emit an error, even though the message you're using ("Invalid runtime value. Only 'shared' is supported.") suggests that any non-"shared"value is invalid.If you want stricter and more predictable behavior, you could extend the match to also error on non-string expressions for
runtime, reusing the same message. Conceptually:- PropName::Ident(key) if key.sym == "runtime" => { - if let Expr::Lit(Lit::Str(value)) = &*kv.value { - if value.value == "shared" { - return true; - } else { - HANDLER.with(|handler| { - handler - .struct_span_err( - value.span, - "Invalid runtime value. Only 'shared' is supported.", - ) - .emit(); - }); - return false; - } - } - } + PropName::Ident(key) if key.sym == "runtime" => { + match &*kv.value { + Expr::Lit(Lit::Str(value)) if value.value == "shared" => { + return true; + } + Expr::Lit(Lit::Str(value)) => { + HANDLER.with(|handler| { + handler + .struct_span_err( + value.span, + "Invalid runtime value. Only 'shared' is supported.", + ) + .emit(); + }); + return false; + } + other => { + HANDLER.with(|handler| { + handler + .struct_span_err( + other.span(), + "Invalid runtime value. Only 'shared' is supported.", + ) + .emit(); + }); + return false; + } + } + }and similarly for the
PropName::Strcase. This keeps the existing error text (so your new JS test still passes) while making the semantics clearer and rejecting obviously invalid runtime attribute shapes instead of silently ignoring them.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/react/transform/__test__/fixture.spec.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/lib.rs(11 hunks)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1523
File: vitest.config.ts:5-6
Timestamp: 2025-08-13T11:46:43.737Z
Learning: In the lynx-stack codebase, default imports are consistently used for Node.js built-in modules (e.g., `import os from 'node:os'`, `import fs from 'node:fs'`). The TypeScript configuration supports esModuleInterop and allowSyntheticDefaultImports, making default imports the preferred pattern over namespace imports for Node.js built-ins.
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1497
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_full_static.js:9-10
Timestamp: 2025-08-12T16:09:32.413Z
Learning: In the Lynx stack, functions prefixed with `__` that are called in transformed code may be injected globally by the Lynx Engine at runtime rather than exported from the React runtime package. For example, `__CreateFrame` is injected globally by the Lynx Engine, not exported from lynx-js/react.
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1736
File: .changeset/spotty-experts-smoke.md:1-3
Timestamp: 2025-09-12T09:43:04.847Z
Learning: In the lynx-family/lynx-stack repository, private packages (marked with "private": true in package.json) like lynx-js/react-transform don't require meaningful changeset entries even when their public APIs change, since they are not published externally and only affect internal development.
Learnt from: f0rdream
Repo: lynx-family/lynx-stack PR: 1835
File: packages/react/worklet-runtime/src/workletRuntime.ts:52-55
Timestamp: 2025-09-28T08:46:43.177Z
Learning: The legacy worklet path with `_lepusWorkletHash` in `packages/react/worklet-runtime/src/workletRuntime.ts` is preserved for compatibility with MTS (Mini-app Threading Service) that doesn't support Initial Frame Rendering. This path will not be touched in current implementations.
📚 Learning: 2025-09-28T08:46:43.177Z
Learnt from: f0rdream
Repo: lynx-family/lynx-stack PR: 1835
File: packages/react/worklet-runtime/src/workletRuntime.ts:52-55
Timestamp: 2025-09-28T08:46:43.177Z
Learning: The legacy worklet path with `_lepusWorkletHash` in `packages/react/worklet-runtime/src/workletRuntime.ts` is preserved for compatibility with MTS (Mini-app Threading Service) that doesn't support Initial Frame Rendering. This path will not be touched in current implementations.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-27T12:42:01.095Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1616
File: packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js:3-3
Timestamp: 2025-08-27T12:42:01.095Z
Learning: In webpack, properties like __webpack_require__.lynx_ce are injected during compilation/build time when webpack processes modules and generates bundles, not at runtime when dynamic imports execute. Tests for such properties don't need to wait for dynamic imports to complete.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-10-29T10:28:27.519Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1899
File: packages/react/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_static_extract_dynamic_inline_style.js:20-24
Timestamp: 2025-10-29T10:28:27.519Z
Learning: Files inside packages/react/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/ are auto-generated test snapshot files and should not be manually updated. Any issues with the generated code should be addressed in the code generator/transform logic, not in the snapshots themselves.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-21T08:46:54.494Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1370
File: packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts:23-27
Timestamp: 2025-08-21T08:46:54.494Z
Learning: In Lynx webpack runtime modules, the team prioritizes performance and simplicity over defensive runtime error handling. They prefer relying on compile-time type safety (TypeScript) rather than adding runtime checks like try-catch blocks or type validation, especially for performance-critical code like cache event setup/cleanup functions.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-08-11T05:57:18.212Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1305
File: packages/testing-library/testing-environment/src/index.ts:255-258
Timestamp: 2025-08-11T05:57:18.212Z
Learning: In the ReactLynx testing environment (`packages/testing-library/testing-environment/src/index.ts`), the dual assignment pattern `target.console.method = console.method = () => {}` is required for rstest compatibility. This is because rstest provides `console` in an IIFE (Immediately Invoked Function Expression), and both the target and global console need to have these methods defined for proper test execution.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-21T07:21:51.621Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1562
File: packages/react/transform/src/swc_plugin_snapshot/jsx_helpers.rs:261-283
Timestamp: 2025-08-21T07:21:51.621Z
Learning: In packages/react/transform/src/swc_plugin_snapshot/jsx_helpers.rs, the team prefers to keep the original unreachable! logic for JSXSpreadChild in jsx_is_children_full_dynamic function rather than implementing defensive error handling.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-12T16:09:32.413Z
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1497
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_full_static.js:9-10
Timestamp: 2025-08-12T16:09:32.413Z
Learning: In the Lynx stack, functions prefixed with `__` that are called in transformed code may be injected globally by the Lynx Engine at runtime rather than exported from the React runtime package. For example, `__CreateFrame` is injected globally by the Lynx Engine, not exported from lynx-js/react.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-08-11T06:00:04.376Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1305
File: packages/react/testing-library/src/plugins/vitest.ts:59-61
Timestamp: 2025-08-11T06:00:04.376Z
Learning: In the lynx-family/lynx-stack repository, the `testingLibraryPlugin` in `packages/react/testing-library/src/plugins/vitest.ts` intentionally uses `process.exit` when jsdom installation fails, maintaining consistency with the previous implementation from `packages/react/testing-library/src/vitest.config.js`. This behavior should not be changed to use `this.error` despite being a Vite plugin best practice.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-11-05T03:26:52.546Z
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1916
File: packages/react/transform/crates/swc_plugin_snapshot/lib.rs:9-9
Timestamp: 2025-11-05T03:26:52.546Z
Learning: In the lynx-stack repository's swc_core v47 upgrade (PR #1916), the import `use swc_core::atoms as swc_atoms;` is required in files that use the `quote!` macro (e.g., packages/react/transform/crates/swc_plugin_snapshot/lib.rs, swc_plugin_list/lib.rs, swc_plugin_worklet/gen_stmt.rs) even though swc_atoms may not appear explicitly in the source code. This is because the quote! macro generates code that internally references swc_atoms. Removing this import causes compiler error: "failed to resolve: use of unresolved module or unlinked crate `swc_atoms`".
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-09-18T04:43:54.426Z
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1771
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_component_with_static_sibling.js:2-2
Timestamp: 2025-09-18T04:43:54.426Z
Learning: In packages/react/transform/src/swc_plugin_compat/mod.rs, the `add_pure_comment` function at lines 478-482 is specifically for `wrapWithLynxComponent` calls, not `createSnapshot` calls. The PURE comment injection for `createSnapshot` is handled separately in swc_plugin_snapshot/mod.rs. These are two distinct code paths that should be treated differently.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-09-10T11:42:36.855Z
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1714
File: packages/react/transform/Cargo.toml:19-19
Timestamp: 2025-09-10T11:42:36.855Z
Learning: In packages/react/transform/Cargo.toml, the crate uses serde derive macros (#[derive(Serialize, Deserialize)]) in multiple files including src/esbuild.rs and src/swc_plugin_extract_str/mod.rs, so the "derive" feature is required when migrating to workspace dependencies.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
🧬 Code graph analysis (1)
packages/react/transform/crates/swc_plugin_worklet/lib.rs (3)
packages/react/transform/crates/swc_plugin_worklet/extract_ident.rs (1)
new(48-65)packages/react/transform/crates/swc_plugin_worklet/napi.rs (1)
new(104-108)packages/react/transform/swc-plugin-reactlynx/index.d.ts (1)
WorkletVisitorConfig(185-200)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build / Build (Ubuntu)
- GitHub Check: test-rust / Test (Ubuntu)
🔇 Additional comments (4)
packages/react/transform/crates/swc_plugin_worklet/lib.rs (3)
88-91: Consistent propagation ofshared_identifiersinto the extractorAll entry points that build
ExtractingIdentsCollectorConfignow passshared_identifiers: Some(self.shared_identifiers.clone()), so class methods, function declarations, arrows, function expressions, and default-exported functions all share the same shared-runtime identifier skip list.This is exactly what you want for coherent behavior across different worklet shapes; no call site appears to be missing this wiring.
Also applies to: 148-151, 195-198, 250-253, 317-320
367-387: Import pre-scan for shared-runtime identifiers is straightforward and scoped to original module bodyThe import pre-scan in
visit_mut_modulecorrectly:
- Filters only
ImportDecls.- Uses
is_shared_runtime_importto gate work.- Inserts the
localside of named/default/namespace specifiers intoself.shared_identifiersviato_id().Iterating over
&n.bodybeforen.visit_mut_children_with(self)means only the original source imports contribute; the synthetic imports/vars you insert later are naturally ignored, which is exactly what's needed here.
760-963: Shared-runtime tests cover the key shapes and a tricky shadowing caseThe new tests (
should_skip_shared_identifiers_js, default/namespace variants, string-key variant, renamed-import-with-shadowing, and LEPUS target) give good coverage:
- Named, default, and namespace imports with
{ runtime: "shared" }.- Both identifier and string-literal keys in the with-clause.
- A shadowing scenario where a shared-runtime import alias is re-bound in an inner scope.
That should prevent regressions in how
shared_identifiersinteracts with scope analysis.packages/react/transform/__test__/fixture.spec.js (1)
1382-1419: Error-path test for invalid runtime value is precise and well scopedThis test clearly exercises the new HANDLER-based error path for
runtime: "invalid"on a worklet module and asserts both:
- A single error is produced.
- The error text matches the Rust-side message.
That’s a good regression test for the shared-runtime import validation without over-constraining locations or other fields.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/react/transform/crates/swc_plugin_worklet/lib.rs (2)
88-91: Consider avoiding repeated cloning ofshared_identifiersPassing
Some(self.shared_identifiers.clone())intoExtractingIdentsCollectorConfigat each call site is functionally fine, but it does allocate a fresh set on every worklet extraction. If the number of shared imports grows, you might want to switch the config to hold a borrowed or shared reference (e.g.&FxHashSet<Id>orArc<FxHashSet<Id>>) to avoid cloning while keeping semantics the same.Also applies to: 148-151, 195-198, 250-253, 317-320
367-387: Shared-runtime import detection and validation behaviorThe module pre-scan plus
is_shared_runtime_importcorrectly:
- Picks up named/default/namespace specifiers under
with { runtime: "shared" }and records their local ids as shared so they’re skipped during capture.- Handles both identifier and string-literal keys for
"runtime".- Emits a diagnostic when
runtimeis a string literal but not"shared", then treats the import as non-shared.Two minor follow-ups you could consider:
- Factor the duplicated “invalid runtime value” branch for ident vs string keys into a small helper to keep future changes to the error message in one place.
- Optionally log or explicitly ignore cases where
runtimeexists but isn’t a string literal, so unsupported forms don’t silently behave like ordinary imports.Neither is blocking, the current behavior is coherent with the tests.
Also applies to: 467-515
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
.changeset/shared-runtime-imports.md(1 hunks)packages/react/transform/__test__/fixture.spec.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/extract_ident.rs(2 hunks)packages/react/transform/crates/swc_plugin_worklet/lib.rs(11 hunks)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_handle_renamed_import_shadowing_js.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_default_import_js.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_namespace_import_js.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_string_key_js.js(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .changeset/shared-runtime-imports.md
🚧 Files skipped from review as they are similar to previous changes (7)
- packages/react/transform/crates/swc_plugin_worklet/extract_ident.rs
- packages/react/transform/crates/swc_plugin_worklet/tests/swc_snapshots/lib.rs/should_skip_shared_identifiers_default_import_js.js
- packages/react/transform/crates/swc_plugin_worklet/tests/swc_snapshots/lib.rs/should_skip_shared_identifiers_string_key_js.js
- packages/react/transform/test/fixture.spec.js
- packages/react/transform/crates/swc_plugin_worklet/tests/swc_snapshots/lib.rs/should_skip_shared_identifiers_lepus.js
- packages/react/transform/crates/swc_plugin_worklet/tests/swc_snapshots/lib.rs/should_handle_renamed_import_shadowing_js.js
- packages/react/transform/crates/swc_plugin_worklet/tests/swc_snapshots/lib.rs/should_skip_shared_identifiers_namespace_import_js.js
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1497
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_full_static.js:9-10
Timestamp: 2025-08-12T16:09:32.413Z
Learning: In the Lynx stack, functions prefixed with `__` that are called in transformed code may be injected globally by the Lynx Engine at runtime rather than exported from the React runtime package. For example, `__CreateFrame` is injected globally by the Lynx Engine, not exported from lynx-js/react.
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1523
File: vitest.config.ts:5-6
Timestamp: 2025-08-13T11:46:43.737Z
Learning: In the lynx-stack codebase, default imports are consistently used for Node.js built-in modules (e.g., `import os from 'node:os'`, `import fs from 'node:fs'`). The TypeScript configuration supports esModuleInterop and allowSyntheticDefaultImports, making default imports the preferred pattern over namespace imports for Node.js built-ins.
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1736
File: .changeset/spotty-experts-smoke.md:1-3
Timestamp: 2025-09-12T09:43:04.847Z
Learning: In the lynx-family/lynx-stack repository, private packages (marked with "private": true in package.json) like lynx-js/react-transform don't require meaningful changeset entries even when their public APIs change, since they are not published externally and only affect internal development.
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1616
File: packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js:3-3
Timestamp: 2025-08-27T12:42:01.095Z
Learning: In webpack, properties like __webpack_require__.lynx_ce are injected during compilation/build time when webpack processes modules and generates bundles, not at runtime when dynamic imports execute. Tests for such properties don't need to wait for dynamic imports to complete.
📚 Learning: 2025-11-05T03:26:52.546Z
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1916
File: packages/react/transform/crates/swc_plugin_snapshot/lib.rs:9-9
Timestamp: 2025-11-05T03:26:52.546Z
Learning: In the lynx-stack repository's swc_core v47 upgrade (PR #1916), the import `use swc_core::atoms as swc_atoms;` is required in files that use the `quote!` macro (e.g., packages/react/transform/crates/swc_plugin_snapshot/lib.rs, swc_plugin_list/lib.rs, swc_plugin_worklet/gen_stmt.rs) even though swc_atoms may not appear explicitly in the source code. This is because the quote! macro generates code that internally references swc_atoms. Removing this import causes compiler error: "failed to resolve: use of unresolved module or unlinked crate `swc_atoms`".
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-09-28T08:46:43.177Z
Learnt from: f0rdream
Repo: lynx-family/lynx-stack PR: 1835
File: packages/react/worklet-runtime/src/workletRuntime.ts:52-55
Timestamp: 2025-09-28T08:46:43.177Z
Learning: The legacy worklet path with `_lepusWorkletHash` in `packages/react/worklet-runtime/src/workletRuntime.ts` is preserved for compatibility with MTS (Mini-app Threading Service) that doesn't support Initial Frame Rendering. This path will not be touched in current implementations.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rspackages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js
📚 Learning: 2025-09-10T11:42:36.855Z
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1714
File: packages/react/transform/Cargo.toml:19-19
Timestamp: 2025-09-10T11:42:36.855Z
Learning: In packages/react/transform/Cargo.toml, the crate uses serde derive macros (#[derive(Serialize, Deserialize)]) in multiple files including src/esbuild.rs and src/swc_plugin_extract_str/mod.rs, so the "derive" feature is required when migrating to workspace dependencies.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-11T05:57:18.212Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1305
File: packages/testing-library/testing-environment/src/index.ts:255-258
Timestamp: 2025-08-11T05:57:18.212Z
Learning: In the ReactLynx testing environment (`packages/testing-library/testing-environment/src/index.ts`), the dual assignment pattern `target.console.method = console.method = () => {}` is required for rstest compatibility. This is because rstest provides `console` in an IIFE (Immediately Invoked Function Expression), and both the target and global console need to have these methods defined for proper test execution.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-21T07:21:51.621Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1562
File: packages/react/transform/src/swc_plugin_snapshot/jsx_helpers.rs:261-283
Timestamp: 2025-08-21T07:21:51.621Z
Learning: In packages/react/transform/src/swc_plugin_snapshot/jsx_helpers.rs, the team prefers to keep the original unreachable! logic for JSXSpreadChild in jsx_is_children_full_dynamic function rather than implementing defensive error handling.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rspackages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js
📚 Learning: 2025-08-27T12:42:01.095Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1616
File: packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js:3-3
Timestamp: 2025-08-27T12:42:01.095Z
Learning: In webpack, properties like __webpack_require__.lynx_ce are injected during compilation/build time when webpack processes modules and generates bundles, not at runtime when dynamic imports execute. Tests for such properties don't need to wait for dynamic imports to complete.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rspackages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js
📚 Learning: 2025-10-29T10:28:27.519Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1899
File: packages/react/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_static_extract_dynamic_inline_style.js:20-24
Timestamp: 2025-10-29T10:28:27.519Z
Learning: Files inside packages/react/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/ are auto-generated test snapshot files and should not be manually updated. Any issues with the generated code should be addressed in the code generator/transform logic, not in the snapshots themselves.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js
📚 Learning: 2025-09-18T04:43:54.426Z
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1771
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_component_with_static_sibling.js:2-2
Timestamp: 2025-09-18T04:43:54.426Z
Learning: In packages/react/transform/src/swc_plugin_compat/mod.rs, the `add_pure_comment` function at lines 478-482 is specifically for `wrapWithLynxComponent` calls, not `createSnapshot` calls. The PURE comment injection for `createSnapshot` is handled separately in swc_plugin_snapshot/mod.rs. These are two distinct code paths that should be treated differently.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js
📚 Learning: 2025-11-04T10:15:14.965Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1899
File: packages/react/runtime/__test__/snapshotPatch.test.jsx:725-749
Timestamp: 2025-11-04T10:15:14.965Z
Learning: In packages/react/runtime/src/snapshot.ts, the snapshotCreatorMap type signature uses `Record<string, (uniqId: string) => string>` (returning string) rather than void for backward compatibility. Old lazy bundles still use the pattern `const snapshot_xxx = createSnapshot(...)` directly, which requires createSnapshot to return a value. The snapshotCreatorMap creators that wrap createSnapshot calls must maintain the same return type to support these legacy bundles.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js
📚 Learning: 2025-09-18T04:43:54.426Z
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1771
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_component_with_static_sibling.js:2-2
Timestamp: 2025-09-18T04:43:54.426Z
Learning: In the lynx-family/lynx-stack repository, the `add_pure_comment` function in packages/react/transform/src/swc_plugin_compat/mod.rs (around lines 478-482) is specifically for `wrapWithLynxComponent` calls, not `createSnapshot` calls. The PURE comment injection for `createSnapshot` is handled separately in swc_plugin_snapshot/mod.rs.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js
🧬 Code graph analysis (1)
packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js (5)
packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_handle_renamed_import_shadowing_js.js (1)
worklet(6-15)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_default_import_js.js (1)
worklet(4-12)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_lepus.js (2)
worklet(6-11)worklet(13-13)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_namespace_import_js.js (1)
worklet(4-12)packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_string_key_js.js (1)
worklet(4-12)
🔇 Additional comments (3)
packages/react/transform/crates/swc_plugin_worklet/lib.rs (2)
11-16: Shared identifier tracking wiring looks correctUsing a dedicated
FxHashSet<Id>onWorkletVisitorand initializing it innew()is a clean way to track shared-runtime bindings across the visitor. The additional imports (FxHashSet,HANDLER,DUMMY_SP) are consistent with the rest of the file and don’t introduce issues.Also applies to: 55-63, 523-532
760-963: New shared-runtime tests give good coverageThe added tests cover:
- Named, default, and namespace imports with
runtime: "shared".- String-literal and identifier keys for
"runtime".- Shadowing of a shared import by a local binding.
- Both JS and LEPUS transform targets.
This provides solid regression coverage for the new shared-runtime behavior in the worklet transform.
packages/react/transform/crates/swc_plugin_worklet/tests/__swc_snapshots__/lib.rs/should_skip_shared_identifiers_js.js (1)
1-12: Snapshot matches expected shared-runtime behaviorThis snapshot correctly shows only
y1being captured in the worklet object (nosharedRuntime), consistent with the new shared-runtime skipping logic and with the other shared-identifier snapshots. Since files under__swc_snapshots__are generated, there’s nothing to change here by hand.
React Example#6413 Bundle Size — 236.9KiB (0%).abff45c(current) vs f7256d5 main#6408(baseline) Bundle metrics
|
| Current #6413 |
Baseline #6408 |
|
|---|---|---|
0B |
0B |
|
0B |
0B |
|
0% |
0% |
|
0 |
0 |
|
4 |
4 |
|
162 |
162 |
|
65 |
65 |
|
46.74% |
46.74% |
|
2 |
2 |
|
0 |
0 |
Bundle size by type no changes
| Current #6413 |
Baseline #6408 |
|
|---|---|---|
145.76KiB |
145.76KiB |
|
91.14KiB |
91.14KiB |
Bundle analysis report Branch Yradex:mts/dev-2 Project dashboard
Generated by RelativeCI Documentation Report issue
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/react/transform/crates/swc_plugin_worklet/lib.rs (1)
467-537: Consider extracting duplicated error-handling logic.The
PropName::Ident(lines 474-500) andPropName::Str(lines 502-528) branches contain nearly identical logic. Consider extracting a helper to reduce duplication:+fn check_runtime_value(value: &Expr) -> Option<bool> { + if let Expr::Lit(Lit::Str(s)) = value { + if s.value == "shared" { + return Some(true); + } + HANDLER.with(|handler| { + handler + .struct_span_err(s.span, "Invalid runtime value. Only 'shared' is supported.") + .emit(); + }); + return Some(false); + } + HANDLER.with(|handler| { + handler + .struct_span_err(value.span(), "Invalid runtime value. Only 'shared' is supported.") + .emit(); + }); + Some(false) +} fn is_shared_runtime_import(import_decl: &ImportDecl) -> bool { if let Some(with_clause) = &import_decl.with { for prop in &with_clause.props { if let PropOrSpread::Prop(prop) = prop { if let Prop::KeyValue(kv) = &**prop { - match &kv.key { - PropName::Ident(key) if key.sym == "runtime" => { - // ... duplicated logic - } - PropName::Str(s) if s.value == "runtime" => { - // ... duplicated logic - } - _ => {} - } + let is_runtime_key = match &kv.key { + PropName::Ident(key) => key.sym == "runtime", + PropName::Str(s) => s.value == "runtime", + _ => false, + }; + if is_runtime_key { + if let Some(result) = check_runtime_value(&kv.value) { + return result; + } + } } } } } false }This is optional given current code works correctly.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/react/transform/__test__/fixture.spec.js(1 hunks)packages/react/transform/crates/swc_plugin_worklet/lib.rs(11 hunks)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1497
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_full_static.js:9-10
Timestamp: 2025-08-12T16:09:32.413Z
Learning: In the Lynx stack, functions prefixed with `__` that are called in transformed code may be injected globally by the Lynx Engine at runtime rather than exported from the React runtime package. For example, `__CreateFrame` is injected globally by the Lynx Engine, not exported from lynx-js/react.
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1523
File: vitest.config.ts:5-6
Timestamp: 2025-08-13T11:46:43.737Z
Learning: In the lynx-stack codebase, default imports are consistently used for Node.js built-in modules (e.g., `import os from 'node:os'`, `import fs from 'node:fs'`). The TypeScript configuration supports esModuleInterop and allowSyntheticDefaultImports, making default imports the preferred pattern over namespace imports for Node.js built-ins.
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1736
File: .changeset/spotty-experts-smoke.md:1-3
Timestamp: 2025-09-12T09:43:04.847Z
Learning: In the lynx-family/lynx-stack repository, private packages (marked with "private": true in package.json) like lynx-js/react-transform don't require meaningful changeset entries even when their public APIs change, since they are not published externally and only affect internal development.
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1238
File: packages/react/runtime/src/debug/component-stack.ts:70-90
Timestamp: 2025-07-18T04:27:18.291Z
Learning: The component-stack.ts file in packages/react/runtime/src/debug/component-stack.ts is a direct fork from https://github.com/preactjs/preact/blob/main/debug/src/component-stack.js. The team prefers to keep it aligned with the upstream Preact version and may contribute improvements back to Preact in the future.
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1616
File: packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js:3-3
Timestamp: 2025-08-27T12:42:01.095Z
Learning: In webpack, properties like __webpack_require__.lynx_ce are injected during compilation/build time when webpack processes modules and generates bundles, not at runtime when dynamic imports execute. Tests for such properties don't need to wait for dynamic imports to complete.
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1305
File: packages/react/testing-library/src/plugins/vitest.ts:4-6
Timestamp: 2025-08-11T05:59:28.530Z
Learning: In the lynx-family/lynx-stack repository, the `packages/react/testing-library` package does not have `vite` as a direct dependency. It relies on `vitest` being available from the monorepo root and accesses Vite types through re-exports from `vitest/node`. Direct imports from `vite` should not be suggested for this package.
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1916
File: packages/react/transform/crates/swc_plugin_snapshot/lib.rs:9-9
Timestamp: 2025-11-05T03:26:52.546Z
Learning: In the lynx-stack repository's swc_core v47 upgrade (PR #1916), the import `use swc_core::atoms as swc_atoms;` is required in files that use the `quote!` macro (e.g., packages/react/transform/crates/swc_plugin_snapshot/lib.rs, swc_plugin_list/lib.rs, swc_plugin_worklet/gen_stmt.rs) even though swc_atoms may not appear explicitly in the source code. This is because the quote! macro generates code that internally references swc_atoms. Removing this import causes compiler error: "failed to resolve: use of unresolved module or unlinked crate `swc_atoms`".
Learnt from: f0rdream
Repo: lynx-family/lynx-stack PR: 1835
File: packages/react/worklet-runtime/src/workletRuntime.ts:52-55
Timestamp: 2025-09-28T08:46:43.177Z
Learning: The legacy worklet path with `_lepusWorkletHash` in `packages/react/worklet-runtime/src/workletRuntime.ts` is preserved for compatibility with MTS (Mini-app Threading Service) that doesn't support Initial Frame Rendering. This path will not be touched in current implementations.
📚 Learning: 2025-08-27T12:42:01.095Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1616
File: packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js:3-3
Timestamp: 2025-08-27T12:42:01.095Z
Learning: In webpack, properties like __webpack_require__.lynx_ce are injected during compilation/build time when webpack processes modules and generates bundles, not at runtime when dynamic imports execute. Tests for such properties don't need to wait for dynamic imports to complete.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-10-29T10:28:27.519Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1899
File: packages/react/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/lib.rs/should_static_extract_dynamic_inline_style.js:20-24
Timestamp: 2025-10-29T10:28:27.519Z
Learning: Files inside packages/react/transform/crates/swc_plugin_snapshot/tests/__swc_snapshots__/ are auto-generated test snapshot files and should not be manually updated. Any issues with the generated code should be addressed in the code generator/transform logic, not in the snapshots themselves.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-09-28T08:46:43.177Z
Learnt from: f0rdream
Repo: lynx-family/lynx-stack PR: 1835
File: packages/react/worklet-runtime/src/workletRuntime.ts:52-55
Timestamp: 2025-09-28T08:46:43.177Z
Learning: The legacy worklet path with `_lepusWorkletHash` in `packages/react/worklet-runtime/src/workletRuntime.ts` is preserved for compatibility with MTS (Mini-app Threading Service) that doesn't support Initial Frame Rendering. This path will not be touched in current implementations.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-10-11T06:16:12.517Z
Learnt from: Sherry-hue
Repo: lynx-family/lynx-stack PR: 1820
File: packages/web-platform/web-tests/tests/react.spec.ts:834-856
Timestamp: 2025-10-11T06:16:12.517Z
Learning: In packages/web-platform/web-tests/tests/react.spec.ts, the tests `basic-bindmouse` and `basic-mts-bindtouchstart` are NOT duplicates despite having similar test structures. They test different event types: `basic-bindmouse` validates mouse events (mousedown, mouseup, mousemove) with mouse-specific properties (button, buttons, x, y, pageX, pageY, clientX, clientY), while `basic-mts-bindtouchstart` validates touch events (touchstart) with touch arrays (touches, targetTouches, changedTouches). The similar test structure is coincidental and follows testing conventions.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-09-23T08:54:39.966Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1670
File: packages/webpack/css-extract-webpack-plugin/test/hotCases/hot/hot-update-json/dual-thread/__snapshot__/index.css:6-8
Timestamp: 2025-09-23T08:54:39.966Z
Learning: In the lynx-stack CSS extract webpack plugin tests, many test fixture CSS files intentionally use invalid CSS syntax like `color: 'red';` with quoted values. The snapshots correctly reflect this invalid CSS from the source fixtures. To fix CSS validation issues, the source fixture files should be updated first, then snapshots regenerated, rather than manually editing snapshots.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-08-21T08:46:54.494Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1370
File: packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts:23-27
Timestamp: 2025-08-21T08:46:54.494Z
Learning: In Lynx webpack runtime modules, the team prioritizes performance and simplicity over defensive runtime error handling. They prefer relying on compile-time type safety (TypeScript) rather than adding runtime checks like try-catch blocks or type validation, especially for performance-critical code like cache event setup/cleanup functions.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-08-11T05:57:18.212Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1305
File: packages/testing-library/testing-environment/src/index.ts:255-258
Timestamp: 2025-08-11T05:57:18.212Z
Learning: In the ReactLynx testing environment (`packages/testing-library/testing-environment/src/index.ts`), the dual assignment pattern `target.console.method = console.method = () => {}` is required for rstest compatibility. This is because rstest provides `console` in an IIFE (Immediately Invoked Function Expression), and both the target and global console need to have these methods defined for proper test execution.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-21T07:21:51.621Z
Learnt from: upupming
Repo: lynx-family/lynx-stack PR: 1562
File: packages/react/transform/src/swc_plugin_snapshot/jsx_helpers.rs:261-283
Timestamp: 2025-08-21T07:21:51.621Z
Learning: In packages/react/transform/src/swc_plugin_snapshot/jsx_helpers.rs, the team prefers to keep the original unreachable! logic for JSXSpreadChild in jsx_is_children_full_dynamic function rather than implementing defensive error handling.
Applied to files:
packages/react/transform/__test__/fixture.spec.jspackages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-08-12T16:09:32.413Z
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1497
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_full_static.js:9-10
Timestamp: 2025-08-12T16:09:32.413Z
Learning: In the Lynx stack, functions prefixed with `__` that are called in transformed code may be injected globally by the Lynx Engine at runtime rather than exported from the React runtime package. For example, `__CreateFrame` is injected globally by the Lynx Engine, not exported from lynx-js/react.
Applied to files:
packages/react/transform/__test__/fixture.spec.js
📚 Learning: 2025-11-05T03:26:52.546Z
Learnt from: colinaaa
Repo: lynx-family/lynx-stack PR: 1916
File: packages/react/transform/crates/swc_plugin_snapshot/lib.rs:9-9
Timestamp: 2025-11-05T03:26:52.546Z
Learning: In the lynx-stack repository's swc_core v47 upgrade (PR #1916), the import `use swc_core::atoms as swc_atoms;` is required in files that use the `quote!` macro (e.g., packages/react/transform/crates/swc_plugin_snapshot/lib.rs, swc_plugin_list/lib.rs, swc_plugin_worklet/gen_stmt.rs) even though swc_atoms may not appear explicitly in the source code. This is because the quote! macro generates code that internally references swc_atoms. Removing this import causes compiler error: "failed to resolve: use of unresolved module or unlinked crate `swc_atoms`".
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
📚 Learning: 2025-09-10T11:42:36.855Z
Learnt from: gaoachao
Repo: lynx-family/lynx-stack PR: 1714
File: packages/react/transform/Cargo.toml:19-19
Timestamp: 2025-09-10T11:42:36.855Z
Learning: In packages/react/transform/Cargo.toml, the crate uses serde derive macros (#[derive(Serialize, Deserialize)]) in multiple files including src/esbuild.rs and src/swc_plugin_extract_str/mod.rs, so the "derive" feature is required when migrating to workspace dependencies.
Applied to files:
packages/react/transform/crates/swc_plugin_worklet/lib.rs
🧬 Code graph analysis (2)
packages/react/transform/__test__/fixture.spec.js (1)
packages/react/transform/rspack-napi/src/index.ts (1)
transformReactLynx(161-161)
packages/react/transform/crates/swc_plugin_worklet/lib.rs (2)
packages/react/transform/crates/swc_plugin_worklet/extract_ident.rs (1)
new(48-65)packages/react/transform/crates/swc_plugin_worklet/hash.rs (1)
new(8-10)
🔇 Additional comments (5)
packages/react/transform/__test__/fixture.spec.js (1)
1389-1504: LGTM! Good test coverage for error cases.The three tests comprehensively cover the error scenarios for invalid runtime import attributes:
- Invalid runtime value string (
"invalid")- Non-string runtime value (
123)- String literal key with non-string value (
'runtime': 123)This addresses the past review comment about validating runtime values - invalid values now properly emit an error.
packages/react/transform/crates/swc_plugin_worklet/lib.rs (4)
55-63: LGTM! Appropriate choice of data structure.
FxHashSet<Id>is the correct choice for storing shared identifiers - it provides O(1) lookup and uses SWC'sIdtype which includes both the symbol and its syntactic context for proper hygiene.
368-387: LGTM! Correct pre-scan approach for shared imports.The pre-scan correctly:
- Iterates over imports before visiting children
- Handles all import specifier types (Named, Default, Namespace)
- Uses
.local.to_id()which captures both the symbol and syntactic context for proper hygiene-aware comparison
88-91: LGTM! Consistent propagation of shared_identifiers.The
shared_identifiersset is correctly cloned and passed to allExtractingIdentsCollectorinstantiation sites. The clone is necessary since each collector takes ownership, and the overhead is acceptable given typical import counts.
782-985: LGTM! Comprehensive test coverage.Excellent test coverage including:
- All import specifier types (named, default, namespace)
- String literal key variation (
"runtime"vsruntime)- Both transform targets (JS, LEPUS)
- Shadowing scenario to verify hygiene-aware identifier matching
The shadowing test (lines 917-951) is particularly important - it verifies that a locally shadowed variable
sris correctly captured as a closure variable even when the original importsris marked as shared.
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/css-extract-webpack-plugin@0.7.0 ### Minor Changes - **BREAKING CHANGE**: Require `@lynx-js/template-webpack-plugin` 0.10.0. ([#1965](#1965)) - Merge all css chunk and generate a `.css.hot-update.json` file for each bundle. ([#1965](#1965)) ## @lynx-js/template-webpack-plugin@0.10.0 ### Minor Changes - Merge all css chunk and generate a `.css.hot-update.json` file for each bundle. ([#1965](#1965)) ## @lynx-js/react@0.115.1 ### Patch Changes - Auto define lynx.loadLazyBundle when using `import(/* relative path */)`. ([#1956](#1956)) - feat: support declaring cross-thread shared modules via Import Attributes, enabling Main Thread Functions to call standard JS functions directly. ([#1968](#1968)) - Usage: Add `with { runtime: "shared" }` to the `import` statement. For example: ```ts import { func } from './utils.js' with { runtime: 'shared' }; function worklet() { 'main thread'; func(); // callable inside a main thread function } ``` - Limitations: - Only directly imported identifiers are treated as shared; assigning the import to a new variable will result in the loss of this shared capability. - Functions defined within shared modules do not automatically become Main Thread Functions. Accessing main-thread-only APIs (e.g., `MainThreadRef`) will cause errors. ## @lynx-js/rspeedy@0.12.2 ### Patch Changes - Bump Rsbuild v1.6.13 with Rspack v1.6.6. ([#1995](#1995)) - Updated dependencies \[]: - @lynx-js/web-rsbuild-server-middleware@0.19.1 ## @lynx-js/react-rsbuild-plugin@0.12.1 ### Patch Changes - Avoid injecting hot update runtime when dev.hmr or dev.liveReload is set to false. ([#1980](#1980)) - Updated dependencies \[[`553ece1`](553ece1), [`8cdb69d`](8cdb69d), [`8cdb69d`](8cdb69d)]: - @lynx-js/react-webpack-plugin@0.7.3 - @lynx-js/css-extract-webpack-plugin@0.7.0 - @lynx-js/template-webpack-plugin@0.10.0 - @lynx-js/react-alias-rsbuild-plugin@0.12.1 - @lynx-js/use-sync-external-store@1.5.0 - @lynx-js/react-refresh-webpack-plugin@0.3.4 ## @lynx-js/web-constants@0.19.1 ### Patch Changes - Updated dependencies \[]: - @lynx-js/web-worker-rpc@0.19.1 ## @lynx-js/web-core@0.19.1 ### Patch Changes - fix: support CSP for mts ([#1994](#1994)) - Updated dependencies \[[`f7256d5`](f7256d5)]: - @lynx-js/web-mainthread-apis@0.19.1 - @lynx-js/web-worker-runtime@0.19.1 - @lynx-js/web-constants@0.19.1 - @lynx-js/web-worker-rpc@0.19.1 ## @lynx-js/web-mainthread-apis@0.19.1 ### Patch Changes - fix: fix reload lynx-view when `enableCSSSelector` false may cause css style lost ([#1982](#1982)) - Updated dependencies \[]: - @lynx-js/web-constants@0.19.1 ## @lynx-js/web-worker-runtime@0.19.1 ### Patch Changes - Updated dependencies \[[`f7256d5`](f7256d5)]: - @lynx-js/web-mainthread-apis@0.19.1 - @lynx-js/web-constants@0.19.1 - @lynx-js/web-worker-rpc@0.19.1 ## @lynx-js/react-webpack-plugin@0.7.3 ### Patch Changes - Support `@lynx-js/template-webpack-plugin` v0.10.0. ([#1992](#1992)) ## create-rspeedy@0.12.2 ## @lynx-js/react-alias-rsbuild-plugin@0.12.1 ## upgrade-rspeedy@0.12.2 ## @lynx-js/web-core-server@0.19.1 ## @lynx-js/web-rsbuild-server-middleware@0.19.1 ## @lynx-js/web-worker-rpc@0.19.1 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
<!-- Thank you for submitting a pull request! We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request. Upon submission, your pull request will be automatically assigned with reviewers. If you want to learn more about contributing to this project, please visit: https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md. --> <!-- The AI summary below will be auto-generated - feel free to replace it with your own. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Support for declaring cross-thread shared modules via import attributes (e.g. import with runtime: "shared") so main-thread code can reference imported identifiers directly. * **Documentation** * Added docs describing usage and limitations (only directly imported identifiers are treated as shared; shared modules don't auto-promote functions; accessing main-thread-only APIs may error). * **Tests** * New tests and snapshots covering named/default/namespace/shared imports and invalid/non-string runtime values. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Checklist <!--- Check and mark with an "x" --> - [x] Tests updated (or not required). - [ ] Documentation updated (or not required). - [x] Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).
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/css-extract-webpack-plugin@0.7.0 ### Minor Changes - **BREAKING CHANGE**: Require `@lynx-js/template-webpack-plugin` 0.10.0. ([lynx-family#1965](lynx-family#1965)) - Merge all css chunk and generate a `.css.hot-update.json` file for each bundle. ([lynx-family#1965](lynx-family#1965)) ## @lynx-js/template-webpack-plugin@0.10.0 ### Minor Changes - Merge all css chunk and generate a `.css.hot-update.json` file for each bundle. ([lynx-family#1965](lynx-family#1965)) ## @lynx-js/react@0.115.1 ### Patch Changes - Auto define lynx.loadLazyBundle when using `import(/* relative path */)`. ([lynx-family#1956](lynx-family#1956)) - feat: support declaring cross-thread shared modules via Import Attributes, enabling Main Thread Functions to call standard JS functions directly. ([lynx-family#1968](lynx-family#1968)) - Usage: Add `with { runtime: "shared" }` to the `import` statement. For example: ```ts import { func } from './utils.js' with { runtime: 'shared' }; function worklet() { 'main thread'; func(); // callable inside a main thread function } ``` - Limitations: - Only directly imported identifiers are treated as shared; assigning the import to a new variable will result in the loss of this shared capability. - Functions defined within shared modules do not automatically become Main Thread Functions. Accessing main-thread-only APIs (e.g., `MainThreadRef`) will cause errors. ## @lynx-js/rspeedy@0.12.2 ### Patch Changes - Bump Rsbuild v1.6.13 with Rspack v1.6.6. ([lynx-family#1995](lynx-family#1995)) - Updated dependencies \[]: - @lynx-js/web-rsbuild-server-middleware@0.19.1 ## @lynx-js/react-rsbuild-plugin@0.12.1 ### Patch Changes - Avoid injecting hot update runtime when dev.hmr or dev.liveReload is set to false. ([lynx-family#1980](lynx-family#1980)) - Updated dependencies \[[`553ece1`](lynx-family@553ece1), [`8cdb69d`](lynx-family@8cdb69d), [`8cdb69d`](lynx-family@8cdb69d)]: - @lynx-js/react-webpack-plugin@0.7.3 - @lynx-js/css-extract-webpack-plugin@0.7.0 - @lynx-js/template-webpack-plugin@0.10.0 - @lynx-js/react-alias-rsbuild-plugin@0.12.1 - @lynx-js/use-sync-external-store@1.5.0 - @lynx-js/react-refresh-webpack-plugin@0.3.4 ## @lynx-js/web-constants@0.19.1 ### Patch Changes - Updated dependencies \[]: - @lynx-js/web-worker-rpc@0.19.1 ## @lynx-js/web-core@0.19.1 ### Patch Changes - fix: support CSP for mts ([lynx-family#1994](lynx-family#1994)) - Updated dependencies \[[`f7256d5`](lynx-family@f7256d5)]: - @lynx-js/web-mainthread-apis@0.19.1 - @lynx-js/web-worker-runtime@0.19.1 - @lynx-js/web-constants@0.19.1 - @lynx-js/web-worker-rpc@0.19.1 ## @lynx-js/web-mainthread-apis@0.19.1 ### Patch Changes - fix: fix reload lynx-view when `enableCSSSelector` false may cause css style lost ([lynx-family#1982](lynx-family#1982)) - Updated dependencies \[]: - @lynx-js/web-constants@0.19.1 ## @lynx-js/web-worker-runtime@0.19.1 ### Patch Changes - Updated dependencies \[[`f7256d5`](lynx-family@f7256d5)]: - @lynx-js/web-mainthread-apis@0.19.1 - @lynx-js/web-constants@0.19.1 - @lynx-js/web-worker-rpc@0.19.1 ## @lynx-js/react-webpack-plugin@0.7.3 ### Patch Changes - Support `@lynx-js/template-webpack-plugin` v0.10.0. ([lynx-family#1992](lynx-family#1992)) ## create-rspeedy@0.12.2 ## @lynx-js/react-alias-rsbuild-plugin@0.12.1 ## upgrade-rspeedy@0.12.2 ## @lynx-js/web-core-server@0.19.1 ## @lynx-js/web-rsbuild-server-middleware@0.19.1 ## @lynx-js/web-worker-rpc@0.19.1 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.
Checklist