StackBlitz Git rollback leaves preview stale after dependency change
0 reputation · 20 May 2025, 03:36 UTC
0 reputation · 20 May 2025, 03:36 UTC
StackBlitz’s live preview rebuilds whenever files are saved, including configuration changes such as package.json updates. However, when a user performs a Git rollback to a previous commit, the file system is reverted but the preview iframe may still serve bundles cached from the prior build.
This can result in a mismatch between the source code and the running preview, especially after schema‑changing commits like adding or removing a dependency. The platform does not automatically invalidate its internal module cache after a rollback, and there is no exposed “reset preview” command.
Should StackBlitz automatically trigger a hard reload of the preview when a Git reset occurs, or should it provide an explicit reset option for the user to ensure the preview reflects the rolled‑back state?
31775 reputation · 20 May 2025, 04:21 UTC
Yes — after a Git rollback, StackBlitz’s preview can keep serving bundles built from the pre‑rollback state. The most likely cause is that the rollback rewrites files outside the editor’s file‑watching path, so the dev server never receives a change event that would trigger a rebuild. In addition, the dependency install cache (node_modules) and the bundler’s module cache are not keyed to Git operations, so they stay stale until the user forces a reinstall or restart.
StackBlitz does not publicly document its cache‑invalidation behavior around Git operations in detail, and the exact behavior may vary with project type (Vite, Webpack, Angular CLI, etc.). Treat this explanation as the most probable cause, not a confirmed internal fact.
Because the rollback changed package.json, a simple browser refresh is not enough — the installed dependency graph itself is stale. Follow these steps in order:
node_modules matches the rolled‑back manifest:
npm installnpm run devYou can confirm the missed‑invalidation hypothesis before changing anything:
An automatic hard reload on every Git reset would guarantee consistency, but at a real cost: most rollbacks touch only source files, and forcing a full reinstall and rebuild each time would be slow and wasteful. That trade‑off is why platforms generally leave cache invalidation to the user rather than coupling it to VCS operations.
An explicit reset preview / restart server command is the better UX compromise. It makes invalidation intentional, avoids surprise multi‑second rebuilds after routine history operations, and gives users a deterministic recovery path when source and preview visibly diverge. Until such a command exists, the manual sequence above—reinstall, restart the dev server, then refresh—is the reliable equivalent.
If you can share which dev server the project uses (Vite, Webpack, Angular CLI, etc.), the answer can be narrowed further, as some servers persist their own pre‑bundle caches (for example Vite’s dependency pre‑bundling) that may need explicit clearing after a dependency‑graph change.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.