Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/signals-optimize-include.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@solidjs/vite-plugin': patch
---

Pre-bundle `@solidjs/signals` up front under `vite dev` (and Vitest browser
mode) when the app can import it by name, i.e. it resolves from the project
root. The first optimizer pass otherwise inlines signals into `solid-js`, so a
direct `@solidjs/signals` import from a module the scanner never reached (a
browser-mode test file, a non-literal dynamic import) was a late discovery:
re-optimize and a full page reload ("Vite unexpectedly reloaded a test").
Apps that only get signals transitively (pnpm's isolated layout) are
unchanged.
22 changes: 14 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1517,14 +1517,12 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin[] {
// `solid-js` fails with ERR_MODULE_NOT_FOUND as soon as anything
// externalizes it (vitefu does, once a semi-framework package such as
// `@solidjs/diagnostics` lists it under `dependencies`). With no root
// copy there is nothing to dedupe TO, so the gate loses nothing. Not
// added to `optimizeDeps.include`: the optimizer already reaches
// signals through `solid-js`, and an include entry that doesn't
// resolve from the root logs a warning on every start.
const dedupe =
replaceDev && findPackageDir('@solidjs/signals', path.resolve(projectRoot || process.cwd()))
? [...nestedDeps, '@solidjs/signals']
: nestedDeps;
// copy there is nothing to dedupe TO, so the gate loses nothing.
const rootSignals = !!findPackageDir(
'@solidjs/signals',
path.resolve(projectRoot || process.cwd()),
);
const dedupe = replaceDev && rootSignals ? [...nestedDeps, '@solidjs/signals'] : nestedDeps;

const userTest = (userConfig as any).test ?? {};
const test = {} as any;
Expand Down Expand Up @@ -1664,6 +1662,14 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin[] {
...(command === 'serve'
? ['solid-js/attribution', '@solidjs/web/performance-tracks']
: []),
// An app that depends on `@solidjs/signals` directly can import
// it from a module the scanner never reaches (a test file in
// Vitest browser mode, a non-literal dynamic import). The first
// pass bundled signals inside `solid-js`, so that import is a
// late discovery: re-optimize, full reload. Only when it resolves
// from the root: otherwise the app can't import it by name, and
// an include entry that doesn't resolve warns on every start.
...(command === 'serve' && rootSignals ? ['@solidjs/signals'] : []),
...solidPkgsConfig.optimizeDeps.include,
],
exclude: solidPkgsConfig.optimizeDeps.exclude,
Expand Down
Loading