Skip to content

feat!: default resolve roots to empty array#13273

Merged
stormslowly merged 5 commits intomainfrom
feat/roots_2
Mar 12, 2026
Merged

feat!: default resolve roots to empty array#13273
stormslowly merged 5 commits intomainfrom
feat/roots_2

Conversation

@stormslowly
Copy link
Copy Markdown
Contributor

Summary

Breaking Change: resolve.roots defaults to []

Before: resolve.roots defaulted to [context], mirroring webpack's behavior.
After: resolve.roots defaults to [].

Motivation

When resolving an absolute path specifier (e.g., /Users/foo/bar/baz.ts), rspack-resolver first
probes each entry in roots by joining it with the specifier — so roots: [context] causes N
filesystem stat calls on paths like {context}/Users/foo/bar/... before falling through to the
correct absolute path resolution. This is pure IO waste for the common case where an absolute path
is meant to be exactly that.

Server-relative URL resolution (e.g., importing '/static/app.js' and expecting it to resolve
relative to the project root) is a narrow use case. Making roots: [context] the default imposes
unnecessary overhead on every project that never uses this feature.

Migration

If you rely on server-relative URL resolution, explicitly restore the previous behavior:

// rspack.config.js
module.exports = {
  resolve: {
    roots: [__dirname], // previously the default
  },
};

Related links

Checklist

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

Copilot AI review requested due to automatic review settings March 10, 2026 03:06
@stormslowly stormslowly requested a review from hardfist as a code owner March 10, 2026 03:06
@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Mar 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates Rspack’s default resolve.roots behavior to no longer implicitly include the compilation context, aligning the default to an empty list and adjusting tests/cases accordingly.

Changes:

  • Change JS/TS defaults so resolve.roots defaults to [] instead of [context].
  • Change Rust builder defaults so roots is an empty list by default as well.
  • Update defaults snapshots and the resolve/roots config case to explicitly set resolve.roots when needed.

Reviewed changes

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

Show a summary per file
File Description
tests/rspack-test/defaultsCases/default/base.js Updates the defaults snapshot to expect resolve.roots: [].
tests/rspack-test/defaultsCases/config/browserslist.js Updates an inline diff snapshot (notably context/uniqueName lines).
tests/rspack-test/configCases/resolve/roots/rspack.config.js Explicitly sets resolve.roots for the /dir/* resolution test case.
packages/rspack/src/config/types.ts Removes outdated doc text implying roots defaults to context.
packages/rspack/src/config/defaults.ts Drops context from resolve defaults computation and sets default roots: [].
crates/rspack/src/builder/mod.rs Updates Rust-side resolve defaults to use empty roots.

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

You can also share your feedback on Copilot code review. Take the survey.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 826.2 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.3 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

📦 Binary Size-limit

Comparing 9e8222c to fix: huge file dependencies cause range error (#13305) by Cong-Cong Pan

🙈 Size remains the same at 49.11MB

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 10, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing feat/roots_2 (9e8222c) with main (a09154b)

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.

@stormslowly stormslowly requested a review from chenjiahan March 10, 2026 13:20
Copy link
Copy Markdown
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

Could you update the documentation too?

https://v2.rspack.rs/config/resolve#resolveroots

@stormslowly stormslowly requested a review from ahabhgk March 11, 2026 06:08
ahabhgk
ahabhgk previously approved these changes Mar 11, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 11, 2026

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9e8222c
Status: ✅  Deploy successful!
Preview URL: https://f93f446a.rspack-v2.pages.dev
Branch Preview URL: https://feat-roots-2.rspack-v2.pages.dev

View logs

chenjiahan
chenjiahan previously approved these changes Mar 11, 2026
@stormslowly stormslowly merged commit 0d12003 into main Mar 12, 2026
50 checks passed
@stormslowly stormslowly deleted the feat/roots_2 branch March 12, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants