Skip to content

Rspack persistent cache bug repro - v3 - addDependency() - #3

Open
slorber wants to merge 4 commits into
mainfrom
slorber/repro-code-add-dependency
Open

slorber wants to merge 4 commits into
mainfrom
slorber/repro-code-add-dependency

Conversation

@slorber

@slorber slorber commented Mar 7, 2025

Copy link
Copy Markdown
Owner

This is a follow-up of:

Let's consider this scenario:

# Cleanup caches
rm -rf node_modules/.cache

# 1st run - Codegen + Bundle
echo "export const dynamic = 42" > ./src/dynamicFile.js
node test

# 2nd run - Codegen (with === content) + Bundle => loader should not re-run
# Unfortunately, it re-runs for Rspack
echo "export const dynamic = 42" > ./src/dynamicFile.js
node test

# 3rd run - Codegen (with !== content) + Bundle => loader should re-run !
echo "export const dynamic = 82" > ./src/dynamicFile.js
node test

The loader adds this dynamic file as a dependency:

  this.addDependency(
    require("path").relative(process.cwd(), "./src/dynamicFile.js"),
  );

Webpack behavior

1st run: js files are compiled as expected

Bundle App start - WEBPACK
- Loading src/entry.js
- Loading src/file.js
Bundle App: 2.143s

2nd run: the dependency is re-created but didn't change, so Webpack doesn't recompile the js files

Bundle App start - WEBPACK
Bundle App: 35.386ms

3rd run: this is surprising, not sure why Webpack doesn't recompile them considering the dependency content changed

Bundle App start - WEBPACK
Bundle App: 35.201ms

Rspack behavior

1st run: js files are compiled as expected

Bundle App start - RSPACK
- Loading src/entry.js
- Loading src/file.js
Bundle App: 2.081s

2nd run: the dependency is re-created but didn't change

⚠️ Rspack always recompiles them, unlike webpack

Bundle App start - RSPACK
- Loading src/entry.js
- Loading src/file.js
Bundle App: 2.030s

3rd run: the dependency content changes, so it looks fine to recompile:

Bundle App start - RSPACK
- Loading src/entry.js
- Loading src/file.js
Bundle App: 2.029s

How to fix that?

On the 2nd CLI run, I'd like the Rspack compilation to be as fast as the Webpack one.

To me, this is the exact same case as #2, using last modified time instead of file content hash to figure out if a file should be recompiled (v2 case), or if the files that depend on it should be recompiled (v3 case)

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.

1 participant