Skip to content

fix(web-core): conditionally include Card and Component only when cardType !== 'react'.#2610

Merged
gaoachao merged 2 commits into
mainfrom
fix/web-core-react-card-sandbox-params
May 12, 2026
Merged

fix(web-core): conditionally include Card and Component only when cardType !== 'react'.#2610
gaoachao merged 2 commits into
mainfrom
fix/web-core-react-card-sandbox-params

Conversation

@gaoachao
Copy link
Copy Markdown
Collaborator

@gaoachao gaoachao commented May 12, 2026

Conditionally include Card and Component only when cardType !== 'react'.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved parameter handling for Card and Component initialization in the background thread based on card type, ensuring proper conditional parameter passing during runtime setup.

Review Change Stack

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

ReactLynx bundles do not declare `Card` and `Component` in their
function signature. Passing these params unconditionally shifted all
subsequent parameter positions, causing `lynx` to be `undefined` and
triggering `loadCard failed TypeError: Cannot read properties of
undefined (reading 'performance')`.

Conditionally include `Card` and `Component` only when
`cardType !== 'react'`.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

📝 Walkthrough

Walkthrough

Background thread initialization now threads cardType through the startup chain (startBackgroundThreadcreateNativeAppcreateChunkLoading) to conditionally inject Card and Component runtime bindings. The chunk-loading runtime's parameter list and argument array are assembled dynamically based on cardType, and the function is invoked via .apply() to support variable parameters.

Changes

CardType-driven Parameter Injection

Layer / File(s) Summary
CardType parameter threading and conditional injection
.changeset/curvy-shrimps-stay.md, packages/web-platform/web-core/ts/client/background/background-apis/startBackgroundThread.ts, packages/web-platform/web-core/ts/client/background/background-apis/createNativeApp.ts, packages/web-platform/web-core/ts/client/background/background-apis/createChunkLoading.ts
cardType flows from startBackgroundThread through createNativeApp to createChunkLoading, which conditionally assembles parameter names and arguments for the generated runtime function, binding tt.Card and/or tt.Component based on the provided card type. The generated function is invoked via .apply() to handle variable parameter lists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • lynx-family/lynx-stack#1922: Both PRs modify how Card/Component entrypoints are injected into the chunk-loading runtime (this PR adds conditional inclusion by cardType; referenced PR changes to pass bound tt.Card/tt.Component).
  • lynx-family/lynx-stack#2562: Both PRs modify createChunkLoading.ts's bundle-init wrapper and the set of runtime bindings passed into the generated Function (this PR adds conditional Card/Component params keyed by cardType; referenced PR removes the injected fetch binding).
  • lynx-family/lynx-stack#1834: Both PRs modify the chunk-loading initialization and how bundle init parameters are constructed and invoked.

Suggested labels

platform:Web

Suggested reviewers

  • PupilTong
  • Sherry-hue

Poem

🐰 A card type arrives in the thread, so neat,
Threading through functions with parameter beat,
Conditional bindings—Card when they fit,
Dynamic args dance, apply makes it lit! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: conditionally including Card and Component parameters based on cardType value, which is the core fix documented throughout the changeset and commit messages.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/web-core-react-card-sandbox-params

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.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2026

🦋 Changeset detected

Latest commit: 1c2e35e

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

This PR includes changesets to release 9 packages
Name Type
@lynx-js/web-core Patch
upgrade-rspeedy Patch
@lynx-js/web-rsbuild-server-middleware Patch
@lynx-js/template-webpack-plugin Patch
@lynx-js/react-rsbuild-plugin Patch
create-rspeedy Patch
@lynx-js/web-worker-rpc Patch
@lynx-js/react-alias-rsbuild-plugin Patch
@lynx-js/rspeedy Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gaoachao gaoachao marked this pull request as ready for review May 12, 2026 09:26
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

🧹 Nitpick comments (1)
packages/web-platform/web-core/ts/client/background/background-apis/createChunkLoading.ts (1)

113-152: ⚡ Quick win

Type safety degraded by .apply() invocation pattern.

The refactor from direct invocation to (foo as Function).apply(undefined, args) (line 152) loses the BTSChunkEntry type constraint. TypeScript can no longer verify that the args array matches the function signature constructed in paramNames.

While this change is necessary to support variable-length parameters, consider whether the BTSChunkEntry type definition should be updated to reflect that the function signature is now dynamic, or add runtime assertions to verify paramNames.length === args.length before invocation to catch mismatches during development.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/web-platform/web-core/ts/client/background/background-apis/createChunkLoading.ts`
around lines 113 - 152, The change to call the chunk entry via (foo as
Function).apply(undefined, args) loses the BTSChunkEntry type safety and risks
signature mismatches; restore safety by either updating the BTSChunkEntry type
to accept a variadic signature matching paramNames or add a runtime assertion
before invocation that paramNames.length === args.length (and throw/log a clear
error referencing foo and paramNames on mismatch). Ensure the check is performed
where args is constructed and before (foo as Function).apply(...) so callers
like foo, args, paramNames and the BTSChunkEntry type are kept consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/web-platform/web-core/ts/client/background/background-apis/createChunkLoading.ts`:
- Around line 65-76: BTSChunkEntry's function signature in BTSChunk.ts doesn't
match runtime creation in createChunkLoading.ts because paramNames/args include
Card and Component only when cardType !== 'react'; update BTSChunkEntry to
reflect both variants by adding overloads or conditional types (e.g., one
signature with Card and Component parameters and one without) so the type aligns
with the conditional runtime parameters, or alternatively change
createChunkLoading.ts to always include Card and Component in paramNames/args;
locate BTSChunkEntry, createChunkLoading.ts paramNames/args, and the cast "as
BTSChunkEntry" to apply the fix.

---

Nitpick comments:
In
`@packages/web-platform/web-core/ts/client/background/background-apis/createChunkLoading.ts`:
- Around line 113-152: The change to call the chunk entry via (foo as
Function).apply(undefined, args) loses the BTSChunkEntry type safety and risks
signature mismatches; restore safety by either updating the BTSChunkEntry type
to accept a variadic signature matching paramNames or add a runtime assertion
before invocation that paramNames.length === args.length (and throw/log a clear
error referencing foo and paramNames on mismatch). Ensure the check is performed
where args is constructed and before (foo as Function).apply(...) so callers
like foo, args, paramNames and the BTSChunkEntry type are kept consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6a056349-93f9-45a5-b027-7e29457ec69b

📥 Commits

Reviewing files that changed from the base of the PR and between 460ddbd and 1c2e35e.

📒 Files selected for processing (4)
  • .changeset/curvy-shrimps-stay.md
  • packages/web-platform/web-core/ts/client/background/background-apis/createChunkLoading.ts
  • packages/web-platform/web-core/ts/client/background/background-apis/createNativeApp.ts
  • packages/web-platform/web-core/ts/client/background/background-apis/startBackgroundThread.ts

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

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

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 12, 2026

Merging this PR will improve performance by 17.09%

⚡ 1 improved benchmark
✅ 80 untouched benchmarks
⏩ 26 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
transform 1000 view elements 46.9 ms 40 ms +17.09%

Comparing fix/web-core-react-card-sandbox-params (1c2e35e) with main (460ddbd)

Open in CodSpeed

Footnotes

  1. 26 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 May 12, 2026

React Example with Element Template

#340 Bundle Size — 197.79KiB (0%).

1c2e35e(current) vs 460ddbd main#331(baseline)

Bundle metrics  Change 2 changes
                 Current
#340
     Baseline
#331
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
Change  Modules 81(+2.53%) 79
No change  Duplicate Modules 23 23
Change  Duplicate Code 40.29%(-0.07%) 40.32%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#340
     Baseline
#331
No change  IMG 145.76KiB 145.76KiB
No change  Other 52.03KiB 52.03KiB

Bundle analysis reportBranch fix/web-core-react-card-sandbox-...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 12, 2026

React Example

#8074 Bundle Size — 235.77KiB (0%).

1c2e35e(current) vs 460ddbd main#8065(baseline)

Bundle metrics  no changes
                 Current
#8074
     Baseline
#8065
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 197 197
No change  Duplicate Modules 80 80
No change  Duplicate Code 44.85% 44.85%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8074
     Baseline
#8065
No change  IMG 145.76KiB 145.76KiB
No change  Other 90.01KiB 90.01KiB

Bundle analysis reportBranch fix/web-core-react-card-sandbox-...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 12, 2026

React External

#1187 Bundle Size — 690.27KiB (0%).

1c2e35e(current) vs 460ddbd main#1178(baseline)

Bundle metrics  no changes
                 Current
#1187
     Baseline
#1178
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1187
     Baseline
#1178
No change  Other 690.27KiB 690.27KiB

Bundle analysis reportBranch fix/web-core-react-card-sandbox-...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 12, 2026

Web Explorer

#9647 Bundle Size — 901.38KiB (+0.01%).

1c2e35e(current) vs 460ddbd main#9638(baseline)

Bundle metrics  Change 3 changes
                 Current
#9647
     Baseline
#9638
No change  Initial JS 45.06KiB 45.06KiB
No change  Initial CSS 2.22KiB 2.22KiB
Change  Cache Invalidation 1.53% 32.89%
No change  Chunks 9 9
No change  Assets 11 11
Change  Modules 229(+0.44%) 228
No change  Duplicate Modules 11 11
Change  Duplicate Code 27.22%(-0.11%) 27.25%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#9647
     Baseline
#9638
Regression  JS 497.1KiB (+0.02%) 497KiB
No change  Other 402.06KiB 402.06KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch fix/web-core-react-card-sandbox-...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 12, 2026

React MTF Example

#1205 Bundle Size — 206.65KiB (0%).

1c2e35e(current) vs 460ddbd main#1196(baseline)

Bundle metrics  no changes
                 Current
#1205
     Baseline
#1196
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 0% 46.16%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 192 192
No change  Duplicate Modules 77 77
No change  Duplicate Code 44.36% 44.36%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#1205
     Baseline
#1196
No change  IMG 111.23KiB 111.23KiB
No change  Other 95.42KiB 95.42KiB

Bundle analysis reportBranch fix/web-core-react-card-sandbox-...Project dashboard


Generated by RelativeCIDocumentationReport issue

@gaoachao gaoachao enabled auto-merge (squash) May 12, 2026 09:51
@gaoachao gaoachao merged commit ded4de9 into main May 12, 2026
83 of 85 checks passed
@gaoachao gaoachao deleted the fix/web-core-react-card-sandbox-params branch May 12, 2026 09:54
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