`build --watch`: replacing a symlinked input to point to a different file leaves rebuilds bundling the previous target
Describe the bug
src/link.js is a symbolic link targeting ../store/a.js and is imported by the entry module. If you replace that symlink while vite build --watch is active so that it points to ../store/b.js instead (by creating a temporary symlink beside it and atomically renaming it over src/link.js), two things occur:
- No rebuild starts when the symlink is replaced.
- Editing another module afterward triggers a rebuild, yet the generated bundle still includes the contents of
store/a.js. Only stopping watch mode and running a fresh build producesstore/b.js.
Expected behavior: rebuilds should follow the updated symlink and bundle store/b.js.
This happens regardless of whether a.js and b.js share the same modification time or have different timestamps, and it reproduces on both Vite 8.3.7 and 8.3.8.
To isolate Vite's behavior from Rolldown's, I tested the exact same project files with standalone rolldown -c -w (using both rolldown 1.2.19, which Vite 8.3.8 installs, and 1.3.2). The missing rebuild on symlink replacement still happens, but the stale-content bug does not: once another module is modified and a rebuild runs, Rolldown bundles store/b.js. This indicates that the stale target is retained by Vite, whereas the missed change event comes from the watcher.
Reproduction
https://github.com/KurathSec/vite-build-watch-symlink-retargeted
Steps to reproduce
npm install
ln -sfn ../store/a.js src/link.js
npx vite build --ssr src/main.js --watch
# in a second terminal:
ln -s ../store/b.js src/.link.tmp && mv -T src/.link.tmp src/link.js
# no rebuild occurs; dist/main.js still contains TARGET_A
echo "export default 'PLAIN2';" > src/plain.js
# rebuild runs; dist/main.js contains PLAIN2, but still has TARGET_A
Running sh run.sh automates the same sequence and outputs plain_edit_followed=yes, new_target_shown=no, later_edit_followed=yes, new_target_after_later_edit=no, and fresh_build=yes.
To compare against standalone Rolldown in the same repository directory:
ln -sfn ../store/a.js src/link.js
echo "export default { input: 'src/main.js', output: { file: 'dist/main.js' } };" > rolldown.config.js
npx rolldown -c -w
Repeating the same two steps shows that after editing src/plain.js, dist/main.js contains TARGET_B.
System Info
System:
OS: Linux 7.3 Fedora Linux 44 (Workstation Edition)
CPU: (16) x64 Intel(R) Core(TM) Ultra 9 285H
Memory: 22.68 GB / 30.83 GB
Container: Yes
Shell: 5.3.9 - /bin/bash
Binaries:
Node: 24.18.0 - /usr/bin/node
npm: 11.16.0 - /usr/bin/npm
pnpm: 12.5.1 - ~/.local/bin/pnpm
Browsers:
Firefox: 159.0.1
Firefox Developer Edition: 159.0.1
npmPackages:
vite: 8.3.8 => 8.3.8
Used Package Manager
npm
Logs
No response
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [x] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [x] The provided reproduction is a minimal reproducible example of the bug.
Hi! Could I investigate this? I’d start with a router hydration test that navigates away from the initial server-rendered route and checks whether segmentHeads still references the old DOM. I’d also verify that removing stale references preserves the active route’s behavior.
I think this comment was meant for a different issue. For this issue i would rather wait for the maintainers to say whether the stale target is vite's to fix.
You’re right. I posted a comment meant for an Angular issue here. Sorry for the mix-up. I’ll wait for the Vite maintainers to confirm whether stale symlink targets in watch mode are in scope. Thanks for pointing it out.
Hey, I was looking at the repro and found the distinction between Vite and standalone Rolldown interesting.
Since Rolldown picks up the new symlink target after another file triggers a rebuild, but Vite continues bundling the old one, I was thinking the stale-content part might be related to how Vite retains resolved module identities or cached transform results across rebuilds.
I'd like to trace that path and check whether the cache needs to be invalidated when a symlink's resolved target changes. A regression test could cover both retargeting the symlink and triggering a subsequent rebuild.
I saw the discussion about waiting for maintainers to confirm whether this belongs in Vite. If it's considered in scope, would you be okay with me investigating and working on the fix?