fix(core): split taskContext to remove node:async_hooks from browser bundle#1244
Merged
Conversation
…bundle
The previously-shared `taskContext` module used `await import(asyncHooksSpecifier)`
to lazily load `node:async_hooks` with a `/* webpackIgnore: true */` magic
comment. The variable specifier defeats Rspack's static analysis, so the
comment is silently ignored and the dependency lands in the browser-runtime
bundle, producing a `Critical dependency: the request of a dependency is
an expression` warning whenever a downstream consumer rebundles
`@rstest/core/browser-runtime`.
Split the module into:
- taskContext.ts — TaskContext interface only
- taskContext.node.ts — createNodeTaskContext() with static
`import { AsyncLocalStorage } from 'node:async_hooks'`
- taskContext.browser.ts — createBrowserTaskContext() with closure
fallback only
The instance is injected via createRstestRuntime(workerState, { taskContext })
so runner.ts and console.ts no longer import any platform-specific module.
Node side constructs the Node impl in runInPool.ts; browser entry constructs
the Browser impl per test file.
9aoy
approved these changes
May 12, 2026
Rsdoctor Bundle Diff AnalysisFound 12 projects in monorepo, 2 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 core/browserPath:
📦 Download Diff Report: core/browser Bundle Diff 📁 core/mainPath:
📦 Download Diff Report: core/main Bundle Diff Generated by Rsdoctor GitHub Action |
fi3ework
added a commit
that referenced
this pull request
May 12, 2026
Browser-mode e2e tests run rstest as a subprocess via `runBrowserCli` & siblings, so any Rsbuild/Rspack build warning or Node deprecation lands in `cli.stdout`/`cli.stderr` and is otherwise silently swallowed by the parent test runner. Decorate `expectExecSuccess` returned by the three browser-mode helpers to additionally scan the captured CLI output for framework warning markers (`Build warning:`, `Critical dependency:`, `DeprecationWarning:`, `MODULE_TYPELESS_PACKAGE_JSON`). Any hit fails the test with the offending lines included in the message. This turns regressions like an `await import(<var>)` dynamic specifier losing its `webpackIgnore` magic comment into explicit, debuggable test failures instead of invisible noise. Refs: #1244
3 tasks
fi3ework
added a commit
that referenced
this pull request
May 12, 2026
Browser-mode e2e tests run rstest as a subprocess via `runBrowserCli` & siblings, so any Rsbuild/Rspack build warning or Node deprecation lands in `cli.stdout`/`cli.stderr` and is otherwise silently swallowed by the parent test runner. Decorate `expectExecSuccess` returned by the three browser-mode helpers to additionally scan the captured CLI output for framework warning markers (`Build warning:`, `Critical dependency:`, `DeprecationWarning:`, `MODULE_TYPELESS_PACKAGE_JSON`). Any hit fails the test with the offending lines included in the message. This turns regressions like an `await import(<var>)` dynamic specifier losing its `webpackIgnore` magic comment into explicit, debuggable test failures instead of invisible noise. Refs: #1244
fi3ework
added a commit
that referenced
this pull request
May 12, 2026
Browser-mode e2e tests run rstest as a subprocess via `runBrowserCli` & siblings, so any Rsbuild/Rspack build warning or Node deprecation lands in `cli.stdout`/`cli.stderr` and is otherwise silently swallowed by the parent test runner. Decorate `expectExecSuccess` returned by the three browser-mode helpers to additionally scan the captured CLI output for framework warning markers (`Build warning:`, `Critical dependency:`, `DeprecationWarning:`, `MODULE_TYPELESS_PACKAGE_JSON`). Any hit fails the test with the offending lines included in the message. This turns regressions like an `await import(<var>)` dynamic specifier losing its `webpackIgnore` magic comment into explicit, debuggable test failures instead of invisible noise. Refs: #1244
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Background
CI refined at #1242.
@rstest/core/browser-runtimere-exported a sharedtaskContextmodule that usedawait import(asyncHooksSpecifier)with a/* webpackIgnore: true */magic comment to lazy-loadnode:async_hooks. The variable specifier defeats Rspack's static analysis (the magic comment only applies to literal arguments), sonode:async_hooksended up in the browser bundle and any downstream consumer rebundling that chunk hitsCritical dependency: the request of a dependency is an expression.Implementation
taskContext.tsinto a type-only contract (TaskContext) plus per-platform implementations:taskContext.node.tswith staticimport { AsyncLocalStorage } from 'node:async_hooks'andtaskContext.browser.tswith a closure-only fallback.createRstestRuntime(workerState, { taskContext })sorunner.tsandconsole.tsno longer import any platform-specific module.runInPool.ts; construct the Browser impl per test file in@rstest/browser/client/entry.ts.User Impact
Removes the
Critical dependencywarning when@rstest/core/browser-runtimeis bundled by a downstream consumer (reproducible viaexamples/browser-react).Test plan
pnpm run lint— passpnpm run typecheck— passpnpm run build— passpnpm run test— 370/370 passexamples/browser-reactpnpm test— 6/6 pass, zeroCritical dependencywarnings (previously emitted 3 times per run)silent=passed-only+disableConsoleInterceptcombinations)build/index.test.ts > should write output to customized distPath.rootandbrowser-mode/snapshot.test.ts > should create snapshot files on first run) that pass in isolation and are unrelated to this change