Skip to content

fix(kit): give each devtools storage scope its own directory - #646

Open
0froq wants to merge 2 commits into
vitejs:mainfrom
0froq:fix/kit-storage-scopes
Open

0froq wants to merge 2 commits into
vitejs:mainfrom
0froq:fix/kit-storage-scopes

Conversation

@0froq

@0froq 0froq commented Nov 21, 2026

Copy link
Copy Markdown

This description was drafted by an agent from the diff and the commands it ran. froQ🐸 has reviewed it.

Description

createViteDevToolsHost().getStorageDir() put workspace inside node_modules and returned the same ~/.vite/devtools for both project and global. devframe defines the three scopes as committable and team-shared, per-checkout, and per-user, so saved presets land in a directory that is gitignored and cleared by an install, and nothing is per-checkout at all.

Each scope now gets its own directory: workspace is <workspaceRoot>/.vite-devtools, project is <workspaceRoot>/node_modules/.vite/devtools, and global stays ~/.vite/devtools.

The remote-asset cache in packages/core/src/node/start.ts reads the project scope, so it moves from the home directory into node_modules and rotates with an install, like the rest of the per-checkout data.

Test

packages/kit/src/node/vite-host.test.ts covers the three scopes, that project and global differ, and that workspaceRoot falls back to the Vite root. Four of the five cases fail on main:

AssertionError: expected '/repo/node_modules/.vite/devtools' to be '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/repo/.vite-devtools'
AssertionError: expected '/Users/oQ/.vite/devtools' to be '/repo/node_modules/.vite/devtools'
AssertionError: expected '/Users/oQ/.vite/devtools' not to be '/Users/oQ/.vite/devtools'
AssertionError: expected '/repo/apps/site/node_modules/.vite/de…' to be '/repo/apps/site/.vite-devtools'

Linked Issues

N/A

Additional context

@devframes/plugin-data-inspector already writes its saved queries through both the workspace and project scopes (plugins/data-inspector/src/node/saved-queries.ts), which is what turns the wrong mapping from a theoretical problem into a visible one.

@SaKaNa-Y

Copy link
Copy Markdown
Collaborator

By default, vite-devtools build clears .vite-devtools/ and deletes any shared queries stored there. Is that expected with this PR?

@0froq

0froq commented Nov 22, 2026

Copy link
Copy Markdown
Author

My mistake! I'll move the workspace scope to <workspaceRoot>/.vite/devtools. Thank you!

@0froq
0froq force-pushed the fix/kit-storage-scopes branch from 5adb5ea to cc10c2e Compare November 22, 2026 23:14
@SaKaNa-Y

Copy link
Copy Markdown
Collaborator

I saved a shared query and a private query in the old version, then upgraded. My shared query was still in the list, but Data Inspector treated it as private. My private query disappeared from the list.

We need to handle this migration so users can still find their saved queries.

@0froq

0froq commented Nov 23, 2026

Copy link
Copy Markdown
Author

Took another pass at this. The migration is the problem. If project takes over today's workspace directory, shared data reads as private until it moves, and a late or repeated migration can move private queries into the committable directory. Giving project its own <workspaceRoot>/node_modules/.vite-devtools keeps the old workspace directory as an orphan we can move without ambiguity.

🤔 .vite/devtools is the nicer name, but .vite-devtools migrates cleanly. Which do you prefer? I kind of lean toward .vite-devtools.

@SaKaNa-Y

Copy link
Copy Markdown
Collaborator

I prefer .vite-devtools too. Will the migration also handle private queries saved in ~/.vite/devtools?

@0froq

0froq commented Nov 23, 2026

Copy link
Copy Markdown
Author

Cool, agreed on node_modules/.vite-devtools.

For the migration, the implicit version doesn't hold up. Shared is the easy half, only the workspace scope ever wrote <workspaceRoot>/node_modules/.vite/devtools, so we can move that dir into <workspaceRoot>/.vite/devtools on first run, and project no longer points there, so a late or repeated run can't pick up private data. Private queries are the problem. ~/.vite/devtools/data-inspector/queries.json was written by every project on the machine, and a record has no project in it, so any automatic move is a guess that shows one project's queries inside another.

So the plan is explicit: kit exposes the legacy path, and Data Inspector lists the unclaimed records so users can claim some into this project or discard them. Claimed records remember which project took them, so the next project only sees the rest, or sees all but marks the claimed ones. Discard is for records from a project that's gone, otherwise they keep the file and the notice alive forever. Once nothing is unclaimed the file can be deleted after a while.

Each official plugin needs its own handling here, since only the plugin knows what its files mean. Third-party ones can pick it up from the same API if their authors care.

Settings I'd leave alone. Global and project both wrote ~/.vite/devtools/settings/<ns>.json, so a key is either overwritten or has no known scope, and that file is still read as global, which means old project overrides now apply everywhere. Kit will warn once with the path and people can redo what they care about in the settings UI.

This breaks stored data, maybe it needs a release note and a MIGRATION.md entry. Auth and global settings keep their path, shared data gets moved, and the break stays limited to project-scope data from before the change. Annoying, but that's the debt from the old project data directory.

Upstream, a contract check that the three storage dirs are distinct would have caught this, so I'd add one too.

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.

2 participants