Skip to content

Commit 30f01f6

Browse files
authored
chore: update ssr argument handling (#187)
1 parent c4203bb commit 30f01f6

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.changeset/tame-weeks-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
Handle flexible ssr signature for hooks with ssr argument

packages/vite-plugin-svelte/src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
7171
setupWatchers(options, cache, requestParser);
7272
},
7373

74-
load(id, ssr) {
74+
load(id, opts) {
75+
// @ts-expect-error anticipate vite changing second parameter as options object
76+
// see https://github.com/vitejs/vite/discussions/5109
77+
const ssr: boolean = opts === true || opts?.ssr;
7578
const svelteRequest = requestParser(id, !!ssr);
7679
if (svelteRequest) {
7780
const { filename, query } = svelteRequest;
@@ -91,7 +94,10 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
9194
}
9295
},
9396

94-
async resolveId(importee, importer, customOptions, ssr) {
97+
async resolveId(importee, importer, opts, _ssr) {
98+
// @ts-expect-error anticipate vite changing second parameter as options object
99+
// see https://github.com/vitejs/vite/discussions/5109
100+
const ssr: boolean = _ssr === true || opts.ssr;
95101
const svelteRequest = requestParser(importee, !!ssr);
96102
if (svelteRequest?.query.svelte) {
97103
if (svelteRequest.query.type === 'style') {
@@ -142,7 +148,10 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin {
142148
}
143149
},
144150

145-
async transform(code, id, ssr) {
151+
async transform(code, id, opts) {
152+
// @ts-expect-error anticipate vite changing second parameter as options object
153+
// see https://github.com/vitejs/vite/discussions/5109
154+
const ssr: boolean = opts === true || opts?.ssr;
146155
const svelteRequest = requestParser(id, !!ssr);
147156
if (!svelteRequest) {
148157
return;

0 commit comments

Comments
 (0)