Skip to content

fix(core): avoid cloning URL objects in ESM resolution#1338

Merged
fi3ework merged 2 commits into
mainfrom
9aoy/fix-loader-url-dataclone
May 28, 2026
Merged

fix(core): avoid cloning URL objects in ESM resolution#1338
fi3ework merged 2 commits into
mainfrom
9aoy/fix-loader-url-dataclone

Conversation

@9aoy

@9aoy 9aoy commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes a Node 24 native TypeScript loader interaction where reused non-isolated workers could throw DataCloneError: Cannot clone object of unsupported type. during ESM resolution. Rstest now passes string parent URLs to import.meta.resolve instead of URL objects, preserves absolute specifiers as file:// strings, and keeps bare static imports resolving from the original test path while relative linked assets still resolve from the referencing module.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

Found 13 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 3.7 KB 0
adapter-rslib 24.7 KB 0
adapter-rspack 7.8 KB 0
browser 2.0 MB 0
browser-react 3.7 KB 0
browser-ui 810.0 KB 0
coverage-istanbul 14.5 KB 0
coverage-v8 16.3 KB 0
core/browser 971.9 KB 0
core/loaders 869.0 B 0
core/main 1.7 MB +615.0 B (0.0%)
vscode/extension 27.0 MB 0
vscode/worker 14.5 KB 0
📋 Detailed Reports (Click to expand)

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: 13ed59c88b | PR: #1340

Metric Current Baseline Change
📊 Total Size 1.7 MB 1.7 MB +615.0 B (0.0%)
📄 JavaScript 1.6 MB 1.6 MB +615.0 B (0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 81.6 KB 81.6 KB 0

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

📝 Rstest Ecosystem CI: Open

suite result
rsbuild ❌ failure
examples ✅ success
rspress ✅ success
rslib ✅ success
rsdoctor ✅ success
modernjs ✅ success

@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

📝 Rstest Ecosystem CI: Open

suite result
rspress ✅ success
rsbuild ✅ success
rslib ✅ success
rsdoctor ✅ success
examples ✅ success
modernjs ✅ success

@9aoy 9aoy marked this pull request as ready for review May 28, 2026 11:03
@9aoy 9aoy requested review from Copilot and fi3ework May 28, 2026 11:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a DataCloneError that occurred on Node 24 when reused non-isolated workers ran through Rstest's ESM resolution while Node's native TypeScript loader hook was active. The root cause: passing URL objects across the loader-hook worker boundary triggered structured-clone failures. The fix normalizes the parent argument of import.meta.resolve to a string file:// URL, returns absolute specifiers as href strings, and tightens how the static link callback selects an origin (only relative specifiers use the referencing module; bare specifiers fall back to testPath).

Changes:

  • Centralize import.meta.resolve usage behind a resolveModule helper in both loadEsModule.ts and loadModule.ts, always passing a string parent URL; add a createRequire-based fallback in loadEsModule.ts for environments without import.meta.resolve.
  • Stop passing URL objects for absolute specifiers — use .href strings consistently.
  • In vm.SourceTextModule.link, pass referencingModule.identifier as the origin only for relative specifiers so bare/subpath imports keep resolving from the original test path, and drop the incorrect cast of referencingModule to ImportCallOptions.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/core/src/runtime/worker/loadEsModule.ts Adds resolveModule helper with string parent URL, createRequire fallback; fixes link callback to pass options + origin separately.
packages/core/src/runtime/worker/loadModule.ts Mirrors the resolveModule helper and .href normalization for the CJS-output loader.
packages/core/tests/runner/loadEsModule.test.ts Adds regression tests covering ESM resolution after a native TS load and bare static imports resolving from the test path.
packages/core/tests/runner/fixtures/nativeTsLoader.ts New .ts fixture used to trigger Node's native TypeScript loader before the resolution test.
packages/core/tests/runner/fixtures/bare-parent/package.json New fixture package declaring a #fixture-pkg subpath import.
packages/core/tests/runner/fixtures/bare-parent/bare-parent-pkg/index.mjs Target module for the #fixture-pkg subpath import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fi3ework fi3ework merged commit ffd7429 into main May 28, 2026
15 checks passed
@fi3ework fi3ework deleted the 9aoy/fix-loader-url-dataclone branch May 28, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants