Repository navigation
perf(start-plugin-core): reuse the Rsbuild dev client build when a rebuild cannot change it #8800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattcosta7
wants to merge
8
commits into
TanStack:main
Choose a base branch
from
mattcosta7:perf/rsbuild-dev-client-build-reuse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5bae74e
perf(start-plugin-core): reuse the Rsbuild dev client build when a re…
mattcosta7 a173546
fix(start-plugin-core): include dynamic imports in Rsbuild dev reuse …
mattcosta7 f4075be
perf(start-plugin-core): store digests of Rsbuild dev reuse signatures
mattcosta7 9ad9a6e
fix(start-plugin-core): don't reuse the Rsbuild dev client build afte…
mattcosta7 ac1e563
fix(start-plugin-core): ignore changed watched directories when check…
mattcosta7 2752a53
Merge branch 'main' into perf/rsbuild-dev-client-build-reuse
mattcosta7 0cfcc61
Merge branch 'main' into perf/rsbuild-dev-client-build-reuse
mattcosta7 0edd2b5
Merge branch 'main' into perf/rsbuild-dev-client-build-reuse
mattcosta7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/start-plugin-core': patch | ||
| --- | ||
|
|
||
| Speed up Rsbuild development rebuilds by reusing the client manifest when a rebuild cannot change it, which is typical for code-only edits. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import type { Rspack } from '@rsbuild/core' | ||
|
|
||
| const resolutionConfigFileRegex = | ||
| /(?:^|[\\/])(?:package|[jt]sconfig(?:\.[^\\/]*)?)\.json$/ | ||
|
|
||
| /** | ||
| * A rebuilt dependency can change what its importer sees without the importer | ||
| * itself being rebuilt. | ||
| */ | ||
| export function getRebuiltModulesAndImporters( | ||
| compilation: Rspack.Compilation, | ||
| ): Array<Rspack.Module> { | ||
| const modules = new Set<Rspack.Module>() | ||
| for (const module of compilation.builtModules) { | ||
| modules.add(module) | ||
| for (const connection of compilation.moduleGraph.getIncomingConnections( | ||
| module, | ||
| )) { | ||
| if (connection.originModule) { | ||
| modules.add(connection.originModule) | ||
| } | ||
| } | ||
| } | ||
| return Array.from(modules) | ||
| } | ||
|
|
||
| /** | ||
| * A changed or removed file that no rebuilt module was built from, such as | ||
| * package.json or tsconfig.json, can re-resolve imports in modules that were | ||
| * not rebuilt. | ||
| */ | ||
| export function mayHaveReResolvedImports( | ||
| compiler: Rspack.Compiler, | ||
| compilation: Rspack.Compilation, | ||
| ): boolean { | ||
| if (compiler.removedFiles?.size) { | ||
| return true | ||
| } | ||
| if (!compiler.modifiedFiles?.size) { | ||
| return false | ||
| } | ||
|
|
||
| const rebuiltFiles = new Set<string>() | ||
| for (const module of compilation.builtModules) { | ||
| const file = ( | ||
| module as Rspack.Module & { resourceResolveData?: { path?: string } } | ||
| ).resourceResolveData?.path | ||
| if (file) { | ||
| rebuiltFiles.add(file) | ||
| } | ||
| } | ||
| for (const file of compiler.modifiedFiles) { | ||
| // An imported package.json is rebuilt, but it still configures resolution. | ||
| if (resolutionConfigFileRegex.test(file)) { | ||
| return true | ||
| } | ||
| // A watched directory, such as a Tailwind content path, changes with any | ||
| // file inside it; resolution only reads files, which are listed too. | ||
| if (!rebuiltFiles.has(file) && !compilation.contextDependencies.has(file)) { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reuse check does not detect a module moving between named chunks.
The chunk-graph fingerprint records chunk names, filenames, and module counts, but not which modules each chunk contains (
normalized-client-build.ts:618-628). The import signatures record module identifiers and runtime keys, not chunk membership (:676-721). A comment-only edit that swaps two existingwebpackChunkNamevalues on dynamic imports can therefore move a route module to another chunk while every hashed field stays the same. The chunk names, filenames, module counts, and dynamic-import order do not change.In that case the reuse branch (
:581-584) returns the previousclientBuild. The manifest keeps the oldrouteFilePaths, so preloads and CSS for that route can point at the wrong chunk until a rebuild changes the fingerprint or an import signature. The impact is limited to development, and the next rebuild that changes the chunk graph corrects it.Make chunk membership part of the reuse decision. A membership change must force fresh normalization. Keep hot-update chunks out of the comparison, as the existing filename filter does, so that normal HMR reuse still works.