diff --git a/.changeset/quiet-mirrors-judge.md b/.changeset/quiet-mirrors-judge.md new file mode 100644 index 000000000..0c66999de --- /dev/null +++ b/.changeset/quiet-mirrors-judge.md @@ -0,0 +1,5 @@ +--- +"@solidjs/start": patch +--- + +Fixed fetchEvent flakyness by storing the event in h3 context. diff --git a/packages/start/src/server/fetchEvent.ts b/packages/start/src/server/fetchEvent.ts index b6869c436..a7d5a5633 100644 --- a/packages/start/src/server/fetchEvent.ts +++ b/packages/start/src/server/fetchEvent.ts @@ -13,7 +13,7 @@ import { } from "vinxi/http"; import type { FetchEvent, ResponseStub } from "./types"; -const fetchEventSymbol = Symbol("fetchEvent"); +const fetchEventContext = "solidFetchEvent"; export function createFetchEvent(event: H3Event): FetchEvent { return { @@ -32,12 +32,12 @@ export function cloneEvent(fetchEvent: T): T { } export function getFetchEvent(h3Event: H3Event): FetchEvent { - if (!(h3Event as any)[fetchEventSymbol]) { + if (!h3Event.context[fetchEventContext]) { const fetchEvent = createFetchEvent(h3Event); - (h3Event as any)[fetchEventSymbol] = fetchEvent; + h3Event.context[fetchEventContext] = fetchEvent; } - return (h3Event as any)[fetchEventSymbol]; + return h3Event.context[fetchEventContext]; } export function mergeResponseHeaders(h3Event: H3Event, headers: Headers) {