Skip to content

[Bug]: Rspack persistent cache doesn't work for code-generated files #9413

@slorber

Description

@slorber

System Info

Rspack 1.2.5

Details

When an app file to bundle is code-generated like that:

await fs.promises.writeFile(
  "./src/dynamicFile.js",
  `export const dynamic = 42`,
);

Then Rspack persistent cache will not work as expected: the JS loader will run again on subsequent app compilations.

This also happens when using this.addDependency("./dynamicFile.js")" in a loader.

This differs from Webpack 5 behavior which will cache the file and skip reloading it.

Reproduce link

slorber/rspack-cache-repro#1

Reproduce Steps

Check code on repro/PR: slorber/rspack-cache-repro#1

You can run it with yarn install && yarn test

Here's the console output printing the extra unwanted loader runs

###############################################
# USING WEBPACK
#############

##########
Bundle App start
- Loading src/entry.js
- Loading src/file.js
- Loading src/dynamicFile.js
Bundle App: 2.146s

##########
Bundle App start
Bundle App: 5.507ms

##########
Bundle App start
Bundle App: 4.528ms
###############################################
# USING RSPACK
#############

##########
Bundle App start
- Loading src/entry.js
- Loading src/file.js
- Loading src/dynamicFile.js
Bundle App: 2.032s

##########
Bundle App start
- Loading src/dynamicFile.js ===========> BAD
Bundle App: 1.009s

##########
Bundle App start
- Loading src/dynamicFile.js ===========> BAD
Bundle App: 1.006s

cc @hardfist @jerrykingxyz as requested on Discord

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions