Skip to content

fix: avoid crash on user's CPU does not support simd#2133

Merged
PupilTong merged 2 commits intolynx-family:mainfrom
PupilTong:p/hw/fix-simd128-issue
Jan 23, 2026
Merged

fix: avoid crash on user's CPU does not support simd#2133
PupilTong merged 2 commits intolynx-family:mainfrom
PupilTong:p/hw/fix-simd128-issue

Conversation

@PupilTong
Copy link
Copy Markdown
Collaborator

@PupilTong PupilTong commented Jan 23, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a crash on systems with CPUs that lack SIMD support.
  • Improvements

    • Strengthened runtime capability detection to ensure all required CPU features are present before initializing WASM components, improving stability and compatibility.
  • Tests

    • Updated test environment to cover SIMD-capable scenarios to prevent regressions.

✏️ Tip: You can customize this high-level summary in your review settings.

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 Jan 23, 2026

🦋 Changeset detected

Latest commit: fef070c

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

This PR includes changesets to release 11 packages
Name Type
@lynx-js/web-core Patch
upgrade-rspeedy Patch
@lynx-js/web-rsbuild-server-middleware Patch
@lynx-js/web-core-server Patch
@lynx-js/web-constants Patch
@lynx-js/web-mainthread-apis Patch
@lynx-js/web-worker-rpc Patch
@lynx-js/web-worker-runtime Patch
@lynx-js/rspeedy Patch
@lynx-js/web-core-wasm Patch
create-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

@PupilTong PupilTong requested a review from Sherry-hue January 23, 2026 07:43
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Adds SIMD detection alongside reference-types for WASM feature checks, gating WASM bundle loading on both features; updates tests to mock SIMD and adds a changelog entry documenting a fix for SIMD-related crashes.

Changes

Cohort / File(s) Summary
Changelog
.changeset/bitter-mails-boil.md
Adds a patch changelog entry noting a fix to avoid crashes on CPUs lacking SIMD support.
Test Mocks
packages/web-platform/web-core-wasm/tests/StyleManager.spec.ts, packages/web-platform/web-core-wasm/tests/template-manager.spec.ts
Adds simd: async () => true to the wasm-feature-detect mocks so tests exercise SIMD-enabled code paths.
Client WASM loader
packages/web-platform/web-core-wasm/ts/client/wasm.ts
Imports simd and runs Promise.all([referenceTypes(), simd()]); requires both referenceTypes and simd to be true before loading/compiling the wasm, otherwise rejects with "WASM not supported".
Main-thread WASM init
packages/web-platform/web-mainthread-apis/wasm/index.js
Adds simd import and parallelizes feature detection with Promise.all, switching between standard and legacy wasm chunks based on combined feature support.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • fix: crash on chrome<96 #1361: Modifies WASM feature-detection and conditional-loading logic; this change extends that mechanism to also require SIMD support.

Suggested reviewers

  • Sherry-hue
  • colinaaa

Poem

🐇 I sniff the CPU, twitch my nose,
I check for lanes where SIMD goes.
Two features paired, a careful hop,
Now WASM loads — or we politely stop. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (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 change in the pull request: adding SIMD feature detection to prevent crashes on CPUs without SIMD support.

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


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.

@PupilTong PupilTong self-assigned this Jan 23, 2026
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

🤖 Fix all issues with AI agents
In @.changeset/bitter-mails-boil.md:
- Line 5: The release note line "fix: avoid crash on user's CPU does not support
simd" is grammatically awkward; update the text to a clear, concise phrasing
such as "fix: avoid crash when user's CPU does not support SIMD" (or "fix: avoid
crash on CPUs without SIMD support") to improve clarity and tone—edit the string
in .changeset/bitter-mails-boil.md accordingly.
🧹 Nitpick comments (1)
packages/web-platform/web-core-wasm/ts/client/wasm.ts (1)

6-38: Refactor to async/await for clarity in feature-detection flow.

The feature detection resolves to boolean values (true/false) rather than rejecting, so the current code is safe. However, the async/await pattern aligns better with the project's TypeScript/JavaScript guidelines and makes the conditional logic more readable.

♻️ Suggested refactor
-const wasmLoaded = Promise.all([referenceTypes(), simd()]).then(
-  ([supportsReferenceTypes, supportsSimd]) => {
-    if (supportsReferenceTypes && supportsSimd) {
-      return Promise.all([
-        import(
-          /* webpackMode: "eager" */
-          /* webpackFetchPriority: "high" */
-          /* webpackPrefetch: true */
-          /* webpackPreload: true */
-          '../../binary/client/client.js'
-        ),
-        isWorker ? undefined : WebAssembly.compileStreaming(
-          fetch(
-            new URL(
-              /* webpackChunkName: "standard-wasm" */
-              /* webpackMode: "eager" */
-              /* webpackFetchPriority: "high" */
-              /* webpackPrefetch: true */
-              /* webpackPreload: true */
-              '../../binary/client/client_bg.wasm',
-              import.meta.url,
-            ),
-          ),
-        ),
-      ]);
-    } else {
-      throw new Error('WASM not supported');
-    }
-  },
-);
+const wasmLoaded = (async () => {
+  const [supportsReferenceTypes, supportsSimd] = await Promise.all([
+    referenceTypes(),
+    simd(),
+  ]);
+  if (!supportsReferenceTypes || !supportsSimd) {
+    throw new Error('WASM not supported');
+  }
+  return Promise.all([
+    import(
+      /* webpackMode: "eager" */
+      /* webpackFetchPriority: "high" */
+      /* webpackPrefetch: true */
+      /* webpackPreload: true */
+      '../../binary/client/client.js'
+    ),
+    isWorker ? undefined : WebAssembly.compileStreaming(
+      fetch(
+        new URL(
+          /* webpackChunkName: "standard-wasm" */
+          /* webpackMode: "eager" */
+          /* webpackFetchPriority: "high" */
+          /* webpackPrefetch: true */
+          /* webpackPreload: true */
+          '../../binary/client/client_bg.wasm',
+          import.meta.url,
+        ),
+      ),
+    ),
+  ]);
+})();

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

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

Files with missing lines Patch % Lines
...ges/web-platform/web-mainthread-apis/wasm/index.js 0.00% 6 Missing ⚠️
...kages/web-platform/web-core-wasm/ts/client/wasm.ts 89.47% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jan 23, 2026

Merging this PR will degrade performance by 8.67%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 61 untouched benchmarks
⏩ 3 skipped benchmarks1

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

Performance Changes

Benchmark BASE HEAD Efficiency
basic-performance-nest-level-100 7.1 ms 7.8 ms -8.67%
basic-performance-small-css 8.2 ms 7.8 ms +5.98%

Comparing PupilTong:p/hw/fix-simd128-issue (fef070c) with main (f7133c1)2

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.

  2. No successful run was found on main (4d91dd3) during the generation of this report, so f7133c1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@relativeci
Copy link
Copy Markdown

relativeci bot commented Jan 23, 2026

Web Explorer

#7315 Bundle Size — 384.14KiB (+0.05%).

fef070c(current) vs f7133c1 main#7309(baseline)

Bundle metrics  Change 1 change
                 Current
#7315
     Baseline
#7309
No change  Initial JS 154.12KiB 154.12KiB
No change  Initial CSS 35.05KiB 35.05KiB
Change  Cache Invalidation 7.5% 7.45%
No change  Chunks 8 8
No change  Assets 8 8
No change  Modules 238 238
No change  Duplicate Modules 16 16
No change  Duplicate Code 2.99% 2.99%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#7315
     Baseline
#7309
Regression  JS 252.07KiB (+0.07%) 251.89KiB
No change  Other 97.02KiB 97.02KiB
No change  CSS 35.05KiB 35.05KiB

Bundle analysis reportBranch PupilTong:p/hw/fix-simd128-issueProject dashboard


Generated by RelativeCIDocumentationReport issue

@PupilTong PupilTong merged commit 01c7738 into lynx-family:main Jan 23, 2026
74 of 78 checks passed
colinaaa pushed a commit that referenced this pull request Jan 25, 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/react@0.116.0

### Minor Changes

- **BREAKING CHANGE**: Bump Preact from
[10.24.0](preactjs/preact@1807173)
to
[10.28.0](preactjs/preact@f7693b7),
see diffs at [hzy/preact#6](hzy/preact#6).
([#2042](#2042))

### Patch Changes

- Add safety checks for compilation macros to prevent runtime errors
when they are undefined.
([#2110](#2110))

Replaces direct usage of `__PROFILE__`, `__MAIN_THREAD__`,
`__BACKGROUND__` with `typeof` checks.

This improves robustness by checking variable existence before access,
preventing runtime errors in environments where compilation macros are
not defined.

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

### Minor Changes

- Use `LAYERS` exposed by DSL plugins
([#2114](#2114))

## @lynx-js/gesture-runtime@2.1.2

### Patch Changes

- Fix an issue that `NativeGesture` does not get correct types in
callback ([#2130](#2130))

## @lynx-js/rspeedy@0.13.1

### Patch Changes

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

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

### Patch Changes

- Support using `pluginReactLynx` in Rslib.
([#2114](#2114))

- Updated dependencies
\[[`4cd7182`](4cd7182)]:
    -   @lynx-js/template-webpack-plugin@0.10.2
    -   @lynx-js/react-alias-rsbuild-plugin@0.12.6
    -   @lynx-js/use-sync-external-store@1.5.0
    -   @lynx-js/react-refresh-webpack-plugin@0.3.4
    -   @lynx-js/react-webpack-plugin@0.7.3
    -   @lynx-js/css-extract-webpack-plugin@0.7.0

## upgrade-rspeedy@0.13.1

### Patch Changes

- Fix the issue `rslib-runtime.js` was not published in dist folder.
([#2122](#2122))

## @lynx-js/testing-environment@0.1.10

### Patch Changes

- Fix the error "lynxTestingEnv is not defined"
([#2118](#2118))

## @lynx-js/web-constants@0.19.6

### Patch Changes

- feat: add main-thread API: \_\_QuerySelector
([#2115](#2115))

- fix: when a list-item is deleted from list, the deleted list-item is
still showed incorrectly.
([#1092](#1092))

This is because the `enqueueComponent` method does not delete the node
from the Element Tree. It is only to maintain the display node on RL,
and lynx web needs to delete the dom additionally.

- feat: support main thread invoke ui method
([#2104](#2104))

- feat: support lynx.reload()
([#2127](#2127))

- Updated dependencies
\[[`f7133c1`](f7133c1)]:
    -   @lynx-js/web-worker-rpc@0.19.6

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

### Patch Changes

- fix: avoid crash on CPUs that do not support SIMD
([#2133](#2133))

- feat: support lynx.reload()
([#2127](#2127))

- Updated dependencies
\[[`179f984`](179f984),
[`f7133c1`](f7133c1),
[`6c2b51a`](6c2b51a),
[`556fe9f`](556fe9f),
[`5b589ab`](5b589ab)]:
    -   @lynx-js/web-constants@0.19.6
    -   @lynx-js/web-mainthread-apis@0.19.6
    -   @lynx-js/web-worker-rpc@0.19.6
    -   @lynx-js/web-worker-runtime@0.19.6

## @lynx-js/web-core-wasm@0.0.1

### Patch Changes

- Updated dependencies
\[[`f7133c1`](f7133c1)]:
    -   @lynx-js/web-worker-rpc@0.19.6

## @lynx-js/web-mainthread-apis@0.19.6

### Patch Changes

- feat: add main-thread API: \_\_QuerySelector
([#2115](#2115))

- fix: when a list-item is deleted from list, the deleted list-item is
still showed incorrectly.
([#1092](#1092))

This is because the `enqueueComponent` method does not delete the node
from the Element Tree. It is only to maintain the display node on RL,
and lynx web needs to delete the dom additionally.

- feat: support main thread invoke ui method
([#2104](#2104))

- fix: mts && bts events can be binded both
([#2121](#2121))

- Updated dependencies
\[[`179f984`](179f984),
[`f7133c1`](f7133c1),
[`6c2b51a`](6c2b51a),
[`5b589ab`](5b589ab)]:
    -   @lynx-js/web-constants@0.19.6

## @lynx-js/web-worker-rpc@0.19.6

### Patch Changes

- fix: when a list-item is deleted from list, the deleted list-item is
still showed incorrectly.
([#1092](#1092))

This is because the `enqueueComponent` method does not delete the node
from the Element Tree. It is only to maintain the display node on RL,
and lynx web needs to delete the dom additionally.

## @lynx-js/web-worker-runtime@0.19.6

### Patch Changes

- feat: support lynx.reload()
([#2127](#2127))

- Updated dependencies
\[[`179f984`](179f984),
[`f7133c1`](f7133c1),
[`6c2b51a`](6c2b51a),
[`556fe9f`](556fe9f),
[`5b589ab`](5b589ab)]:
    -   @lynx-js/web-constants@0.19.6
    -   @lynx-js/web-mainthread-apis@0.19.6
    -   @lynx-js/web-worker-rpc@0.19.6

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

### Patch Changes

- Polyfill `lynx.requireModuleAsync` to allow cache same parallel
requests. ([#2108](#2108))

## create-rspeedy@0.13.1



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



## @lynx-js/web-core-server@0.19.6



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

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Mar 25, 2026
3 tasks
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