From b76f056de3e954dc03d3b0b5ac1fd859dc15dfc4 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Thu, 16 Jul 2026 17:15:37 +0200 Subject: [PATCH 1/2] feat: update Vite plugin to use per-environment hook APIs and enhance compatibility for vite 9 compat --- .changeset/tidy-lions-smile.md | 5 +++++ examples/vite-8/vite.config.ts | 5 ++++- package.json | 4 ++-- pnpm-workspace.yaml | 2 +- scripts/test-examples.ts | 15 ++++++++++++--- src/index.ts | 16 +++++++++------- 6 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 .changeset/tidy-lions-smile.md diff --git a/.changeset/tidy-lions-smile.md b/.changeset/tidy-lions-smile.md new file mode 100644 index 0000000..78f70a9 --- /dev/null +++ b/.changeset/tidy-lions-smile.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-solid': patch +--- + +Use per-environment Vite plugin hook APIs while retaining compatibility with Vite 3 through 5. diff --git a/examples/vite-8/vite.config.ts b/examples/vite-8/vite.config.ts index 044b4b7..530b22e 100644 --- a/examples/vite-8/vite.config.ts +++ b/examples/vite-8/vite.config.ts @@ -2,7 +2,10 @@ import { defineConfig } from 'vite'; import solidPlugin from 'vite-plugin-solid'; export default defineConfig({ + future: { + removePluginHookSsrArgument: 'warn', + }, plugins: [ solidPlugin(), ], -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index 56fafe3..6ff144d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-plugin-solid", "version": "2.11.12", - "description": "solid-js integration plugin for vite 3/4/5/6", + "description": "solid-js integration plugin for Vite", "type": "module", "files": [ "dist" @@ -73,7 +73,7 @@ "peerDependencies": { "@testing-library/jest-dom": "^5.16.6 || ^5.17.0 || ^6.*", "solid-js": "^1.7.2", - "vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0" + "vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" }, "peerDependenciesMeta": { "@testing-library/jest-dom": { diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index eaeead6..6b6c4fb 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -2,4 +2,4 @@ packages: - '.' - "examples/*" catalog: - "solid-js": ^1.9.4 \ No newline at end of file + "solid-js": ^1.9.4 diff --git a/scripts/test-examples.ts b/scripts/test-examples.ts index 58ead2d..275f612 100644 --- a/scripts/test-examples.ts +++ b/scripts/test-examples.ts @@ -1,8 +1,14 @@ import { spawn, exec, ChildProcess } from 'node:child_process'; +import { readdirSync } from 'node:fs'; import { promisify } from 'node:util'; const execAsync = promisify(exec); -const examples = ['vite-3', 'vite-4', 'vite-5', 'vite-6']; +const examples = readdirSync('examples', { withFileTypes: true }) + .filter((entry) => entry.isDirectory() && /^vite-\d+$/.test(entry.name)) + .map((entry) => entry.name) + .sort((a, b) => Number(a.slice(5)) - Number(b.slice(5))); +const pluginHookSsrDeprecation = + "Plugin hook `options.ssr` is replaced with `this.environment.config.consumer === 'server'`."; const PORT = 4173; const TEST_TIMEOUT = 5 * 60 * 1000; // 5 minutes @@ -28,7 +34,10 @@ async function runExample(example) { try { // Install and build await execAsync('pnpm install', { cwd: examplePath }); - await execAsync('pnpm run build', { cwd: examplePath }); + const { stdout, stderr } = await execAsync('pnpm run build', { cwd: examplePath }); + if (`${stdout}\n${stderr}`.includes(pluginHookSsrDeprecation)) { + throw new Error(`Vite's deprecated plugin hook SSR argument was used in ${example}`); + } // Start preview server with timeout const server = spawn('pnpm', ['run', 'preview'], { cwd: examplePath }); @@ -75,4 +84,4 @@ runAll().catch(error => { console.error('Unexpected error:', error); cleanup(); process.exit(1); -}); \ No newline at end of file +}); diff --git a/src/index.ts b/src/index.ts index 17e2ea7..250645c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,8 +15,8 @@ const runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs'); const runtimeCode = readFileSync(runtimeFilePath, 'utf-8'); const viteVersionMajor = +version.split('.')[0]; -const isVite6 = viteVersionMajor >= 6; -const isVite8 = viteVersionMajor >= 8; +const isVite6OrNewer = viteVersionMajor >= 6; +const isVite8OrNewer = viteVersionMajor >= 8; /** Possible options for the extensions property */ export interface ExtensionOptions { @@ -266,7 +266,7 @@ export default function solidPlugin(options: Partial = {}): Plugin { */ // esbuild: { include: /\.ts$/ }, resolve: { - conditions: isVite6 + conditions: isVite6OrNewer ? undefined : [ 'solid', @@ -283,11 +283,11 @@ export default function solidPlugin(options: Partial = {}): Plugin { // React's automatic JSX runtime for .tsx files, injecting a // react/jsx-dev-runtime import. Tell it to preserve JSX as-is since // this plugin handles JSX transformation via babel-preset-solid. - ...(isVite8 + ...(isVite8OrNewer ? { rolldownOptions: { transform: { jsx: 'preserve' as const } } } : {}), }, - ...(!isVite6 ? { ssr: solidPkgsConfig.ssr } : {}), + ...(!isVite6OrNewer ? { ssr: solidPkgsConfig.ssr } : {}), ...(test.server ? { test } : {}), }; }, @@ -314,7 +314,7 @@ export default function solidPlugin(options: Partial = {}): Plugin { // Set resolve.noExternal and resolve.external for SSR environment (Vite 6+) // Only set resolve.external if noExternal is not true (to avoid conflicts with plugins like Cloudflare) - if (isVite6 && name === 'ssr' && solidPkgsConfig) { + if (isVite6OrNewer && name === 'ssr' && solidPkgsConfig) { if (config.resolve.noExternal !== true) { config.resolve.noExternal = [ ...(Array.isArray(config.resolve.noExternal) ? config.resolve.noExternal : []), @@ -341,7 +341,9 @@ export default function solidPlugin(options: Partial = {}): Plugin { }, async transform(source, id, transformOptions) { - const isSsr = transformOptions && transformOptions.ssr; + const isSsr = isVite6OrNewer + ? this.environment.config.consumer === 'server' + : Boolean(transformOptions?.ssr); const currentFileExtension = getExtension(id); const extensionsToWatch = options.extensions || []; From 3d0948ca15cddf20532e8f5d0bfd5efd4e60a6be Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Thu, 16 Jul 2026 17:20:35 +0200 Subject: [PATCH 2/2] fix check on .environment --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 250645c..ead2980 100644 --- a/src/index.ts +++ b/src/index.ts @@ -341,7 +341,7 @@ export default function solidPlugin(options: Partial = {}): Plugin { }, async transform(source, id, transformOptions) { - const isSsr = isVite6OrNewer + const isSsr = this.environment ? this.environment.config.consumer === 'server' : Boolean(transformOptions?.ssr); const currentFileExtension = getExtension(id);