Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/sveltekit-handle-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'flags': patch
---

`createHandle` from `flags/sveltekit` now returns a local `Handle` type. SvelteKit 3 moved `Handle` from `@sveltejs/kit` to `@sveltejs/kit/hooks`, so the types of `createHandle` now work with SvelteKit 2 and SvelteKit 3.
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"tailwind-merge": "^3.4.0"
},
"devDependencies": {
"@sveltejs/kit": "^3.1.1",
"@tailwindcss/postcss": "^4.1.17",
"@types/mdx": "^2.0.13",
"@types/node": "^24.10.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/flags/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@types/node": "22.14.0",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"@sveltejs/kit": "^2.70.1",
"@sveltejs/kit": "^3.1.1",
"@vitejs/plugin-react": "6.0.4",
"msw": "2.6.4",
"next": "16.4.3",
Expand Down
20 changes: 19 additions & 1 deletion packages/flags/src/sveltekit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AsyncLocalStorage } from 'node:async_hooks';
import { RequestCookies } from '@edge-runtime/cookies';
import {
error,
type Handle,
json,
type RequestEvent,
type RequestHandler,
Expand Down Expand Up @@ -305,6 +304,25 @@ function createContext(

const flagStorage = new AsyncLocalStorage<AsyncLocalContext>();

/**
* Structural copy of SvelteKit's `Handle` type.
*
* SvelteKit 2 exports `Handle` from `@sveltejs/kit` and SvelteKit 3 exports it
* from `@sveltejs/kit/hooks`. A local type works with both versions.
*/
type Handle = (input: {
event: RequestEvent;
resolve: (
event: RequestEvent,
opts?: {
transformPageChunk?: (input: {
html: string;
done: boolean;
}) => string | undefined | Promise<string | undefined>;
},
) => Promise<Response>;
}) => Response | Promise<Response>;

/**
* Establishes context for flags, so they have access to the
* request and cookie.
Expand Down
Loading
Loading