Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions .changeset/sveltekit-3-peer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'convex-svelte': patch
---

### Fixes

- **Installs with SvelteKit 3** - the optional `@sveltejs/kit` peer dependency is now `^2.12.0 || ^3.0.0`. With `^2.12.0`, npm refused to install `convex-svelte` 0.15.0 next to SvelteKit 3 (`ERESOLVE`).
- **Clear `convexLoadHydration` warning on SvelteKit 3** - SvelteKit 3 no longer marks universal load functions, so the handle can't tell them apart from server loads and embeds nothing (unchanged, fail closed). Its warning used to ask for SvelteKit 2.56 or later; on SvelteKit 3 it now explains the effect and the fix: move `convexLoad()` calls that need auth into `+page.server.ts` / `+layout.server.ts` and remove the handle.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
},
"peerDependencies": {
"@sveltejs/kit": "^2.12.0",
"@sveltejs/kit": "^2.12.0 || ^3.0.0",
"convex": "^1.30.0",
"svelte": "^5.19.0"
},
Expand Down
31 changes: 25 additions & 6 deletions src/lib/sveltekit/hydration-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,40 @@ describe('convexLoadHydration', () => {

describe('convexLoadHydration — SvelteKit without the universal-load marker', () => {
it.each([
['older than 2.31 exports (accessor missing)', { try_get_request_store: undefined }],
['2.31–2.55 (store without the marker)', { try_get_request_store: () => ({ state: {} }) }],
[
'older than 2.31 exports (accessor missing)',
{ try_get_request_store: undefined },
'SvelteKit 2.56'
],
[
'2.31–2.55 (store without the marker)',
{ try_get_request_store: () => ({ state: {} }) },
'SvelteKit 2.56'
],
[
'a store without the remote-function flag',
{ try_get_request_store: () => ({ state: { is_in_universal_load: false } }) }
{ try_get_request_store: () => ({ state: { is_in_universal_load: false } }) },
'SvelteKit 2.56'
],
[
'SvelteKit 3 (no universal-load marker any more)',
{
try_get_request_store: () => ({
state: { is_in_remote_function: false, is_in_remote_query: false }
})
},
'SvelteKit 3'
],
[
'a throwing accessor',
{
try_get_request_store: () => {
throw new Error('internal error');
}
}
},
'SvelteKit 2.56'
]
])('embeds nothing (fail-safe) and warns once: %s', async (_name, internal) => {
])('embeds nothing (fail-safe) and warns once: %s', async (_name, internal, expected) => {
vi.resetModules();
vi.doMock('@sveltejs/kit/internal/server', () => internal);
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
Expand All @@ -286,7 +305,7 @@ describe('convexLoadHydration — SvelteKit without the universal-load marker',

expect(payloadOf(html)).toBeUndefined();
expect(warn).toHaveBeenCalledOnce();
expect(warn.mock.calls[0][0]).toContain('SvelteKit 2.56');
expect(warn.mock.calls[0][0]).toContain(expected);
warn.mockRestore();
vi.doUnmock('@sveltejs/kit/internal/server');
});
Expand Down
18 changes: 15 additions & 3 deletions src/lib/sveltekit/hydration-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ const collectorStorage = new AsyncLocalStorage<HydrationCollector>();
// both flags are needed. There is no public API for them, so read them
// defensively and fail closed: anything but the exact values SvelteKit sets
// means nothing is embedded and convexLoad behaves as without this handle.
type RequestState = { is_in_universal_load?: unknown; is_in_remote_function?: unknown };
type RequestState = {
is_in_universal_load?: unknown;
is_in_remote_function?: unknown;
/** SvelteKit 3 only; used to tell it apart from older SvelteKit 2 versions. */
is_in_remote_query?: unknown;
};
type RequestStore = { state?: RequestState } | null;
const tryGetRequestStore = (
kitInternal as unknown as { try_get_request_store?: () => RequestStore }
Expand Down Expand Up @@ -73,8 +78,15 @@ function checkMarkerSupport(): void {
}
warnedUnsupported = true;
console.warn(
'[convex-svelte] convexLoadHydration needs SvelteKit 2.56 or later to detect universal ' +
'load functions. No convexLoad results are embedded.'
typeof state?.is_in_remote_query === 'boolean'
? '[convex-svelte] convexLoadHydration has no effect on SvelteKit 3 (it no longer marks ' +
'universal load functions), so no convexLoad results are embedded. A convexLoad() in ' +
'+page.ts / +layout.ts now re-runs in the browser before auth is set up. Fix: move ' +
'convexLoad() calls that need auth into +page.server.ts / +layout.server.ts (same code, ' +
'no other change), and remove convexLoadHydration from hooks.server.ts. See ' +
'https://docs.convex.dev/client/svelte/sveltekit-server-rendering#convexloadhydration'
: '[convex-svelte] convexLoadHydration needs SvelteKit 2.56 or later to detect universal ' +
'load functions. No convexLoad results are embedded.'
);
}

Expand Down
Loading