Skip to content

fix: prevent invalid uniqueId of -1 from being added to bubblePath in…#2493

Merged
PupilTong merged 1 commit intolynx-family:mainfrom
PupilTong:p/hw/fix-event-with-invalid-uniqueid
Apr 22, 2026
Merged

fix: prevent invalid uniqueId of -1 from being added to bubblePath in…#2493
PupilTong merged 1 commit intolynx-family:mainfrom
PupilTong:p/hw/fix-event-with-invalid-uniqueid

Conversation

@PupilTong
Copy link
Copy Markdown
Collaborator

@PupilTong PupilTong commented Apr 21, 2026

… WASMJSBinding

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where invalid identifiers were being included in event propagation paths, ensuring more reliable event handling and dispatching.

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

@PupilTong PupilTong requested a review from Sherry-hue as a code owner April 21, 2026 09:21
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 21, 2026

🦋 Changeset detected

Latest commit: b361331

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

This PR introduces a patch-level fix for @lynx-js/web-core to filter out sentinel -1 values when constructing the bubble path in the commonEventHandler. Changes include the implementation fix in WASMJSBinding.ts, a corresponding test case, and a changelog entry.

Changes

Cohort / File(s) Summary
Changeset Entry
.changeset/fix-event-handler-unique-id.md
Added patch-level release note documenting the fix to filter -1 uniqueId values in commonEventHandler.
Test Coverage
packages/web-platform/web-core/tests/element-apis.spec.ts
New test case verifying that mocked common_event_handler is invoked with a bubble path that excludes the sentinel -1 value (represented as 4294967295 in Uint32Array).
Implementation Fix
packages/web-platform/web-core/ts/client/mainthread/elementAPIs/WASMJSBinding.ts
Updated bubble-path construction logic to skip invalid uniqueId values (-1) before appending to bubblePath, ensuring array resizing only accounts for valid entries.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

platform:Web

Suggested reviewers

  • Sherry-hue

Poem

🐰 A sentinel crept through the bubble path so wide,
But -1 had no place here, we filter with pride!
Test and code align now, no invalid IDs stay,
The event chain flows cleaner, hooray hooray! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 change: preventing invalid uniqueId value of -1 from being added to bubblePath in WASMJSBinding, which aligns with the code modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests

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

❤️ Share

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 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!

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 (1)
packages/web-platform/web-core/tests/element-apis.spec.ts (1)

71-79: Assert the valid ancestor remains in bubblePath.

This test would still pass if #commonEventHandler returned an empty path. Please also assert that node1’s valid unique ID is preserved.

Proposed test tightening
     expect(mtsBinding.wasmContext!.common_event_handler).toHaveBeenCalled();
     const calls =
       (mtsBinding.wasmContext!.common_event_handler as any).mock.calls;
-    const bubblePath = calls[0][1] as Uint32Array;
+    const bubblePath = Array.from(calls[0][1] as Uint32Array);
+    const invalidUniqueIdInUint32Array = 0xffffffff;
 
-    // Check that -1 (4294967295 in Uint32Array) is NOT in the bubblePath
-    for (let i = 0; i < bubblePath.length; i++) {
-      expect(bubblePath[i] !== 4294967295).toBe(true);
-    }
+    expect(bubblePath).toEqual([mtsGlobalThis.__GetElementUniqueID(node1)]);
+    expect(bubblePath).not.toContain(invalidUniqueIdInUint32Array);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/web-platform/web-core/tests/element-apis.spec.ts` around lines 71 -
79, The test currently only asserts that -1 isn't present in the bubblePath
returned from mtsBinding.wasmContext!.common_event_handler but would still pass
if the path were empty; update the assertion to also verify that node1's valid
unique ID is included in the bubblePath. After retrieving bubblePath (from
(mtsBinding.wasmContext!.common_event_handler as any).mock.calls[0][1]), compute
or read node1's unique ID (the same identifier used when creating node1) and
assert that bubblePath contains that ID (e.g., convert bubblePath to a normal
array and expect it to contain node1's ID) so the test ensures the ancestor is
preserved.
🤖 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/web-platform/web-core/tests/element-apis.spec.ts`:
- Around line 71-79: The test currently only asserts that -1 isn't present in
the bubblePath returned from mtsBinding.wasmContext!.common_event_handler but
would still pass if the path were empty; update the assertion to also verify
that node1's valid unique ID is included in the bubblePath. After retrieving
bubblePath (from (mtsBinding.wasmContext!.common_event_handler as
any).mock.calls[0][1]), compute or read node1's unique ID (the same identifier
used when creating node1) and assert that bubblePath contains that ID (e.g.,
convert bubblePath to a normal array and expect it to contain node1's ID) so the
test ensures the ancestor is preserved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 48258bf1-107a-4d4e-ad95-5046f713296a

📥 Commits

Reviewing files that changed from the base of the PR and between 02be891 and b361331.

📒 Files selected for processing (3)
  • .changeset/fix-event-handler-unique-id.md
  • packages/web-platform/web-core/tests/element-apis.spec.ts
  • packages/web-platform/web-core/ts/client/mainthread/elementAPIs/WASMJSBinding.ts

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will degrade performance by 16.16%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 79 untouched benchmarks
⏩ 26 skipped benchmarks1

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

Performance Changes

Benchmark BASE HEAD Efficiency
008-many-use-state-destroyBackground 8 ms 9.5 ms -16.16%
transform 1000 view elements 44.6 ms 40 ms +11.59%

Comparing PupilTong:p/hw/fix-event-with-invalid-uniqueid (b361331) with main (02be891)

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

React External

#574 Bundle Size — 583.27KiB (0%).

b361331(current) vs 02be891 main#571(baseline)

Bundle metrics  no changes
                 Current
#574
     Baseline
#571
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
#574
     Baseline
#571
No change  Other 583.27KiB 583.27KiB

Bundle analysis reportBranch PupilTong:p/hw/fix-event-with-in...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 21, 2026

Web Explorer

#9031 Bundle Size — 898.16KiB (~+0.01%).

b361331(current) vs 02be891 main#9028(baseline)

Bundle metrics  Change 1 change
                 Current
#9031
     Baseline
#9028
No change  Initial JS 44.47KiB 44.47KiB
No change  Initial CSS 2.22KiB 2.22KiB
Change  Cache Invalidation 7.99% 0%
No change  Chunks 9 9
No change  Assets 11 11
No change  Modules 229 229
No change  Duplicate Modules 11 11
No change  Duplicate Code 27.22% 27.22%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#9031
     Baseline
#9028
Regression  JS 494.31KiB (~+0.01%) 494.3KiB
No change  Other 401.63KiB 401.63KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch PupilTong:p/hw/fix-event-with-in...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 21, 2026

React Example

#7456 Bundle Size — 224.41KiB (0%).

b361331(current) vs 02be891 main#7453(baseline)

Bundle metrics  no changes
                 Current
#7456
     Baseline
#7453
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 179 179
No change  Duplicate Modules 69 69
No change  Duplicate Code 44.5% 44.5%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#7456
     Baseline
#7453
No change  IMG 145.76KiB 145.76KiB
No change  Other 78.65KiB 78.65KiB

Bundle analysis reportBranch PupilTong:p/hw/fix-event-with-in...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 21, 2026

React MTF Example

#589 Bundle Size — 195.57KiB (0%).

b361331(current) vs 02be891 main#586(baseline)

Bundle metrics  no changes
                 Current
#589
     Baseline
#586
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 173 173
No change  Duplicate Modules 66 66
No change  Duplicate Code 43.99% 43.99%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#589
     Baseline
#586
No change  IMG 111.23KiB 111.23KiB
No change  Other 84.34KiB 84.34KiB

Bundle analysis reportBranch PupilTong:p/hw/fix-event-with-in...Project dashboard


Generated by RelativeCIDocumentationReport issue

@PupilTong PupilTong self-assigned this Apr 21, 2026
@PupilTong PupilTong merged commit 25e196b into lynx-family:main Apr 22, 2026
76 of 79 checks passed
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