Skip to content

Commit

Permalink
fix: store fetchEvent in h3 context (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
katywings authored Jul 23, 2024
1 parent 23b01da commit 65c8ac0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-mirrors-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Fixed fetchEvent flakyness by storing the event in h3 context.
8 changes: 4 additions & 4 deletions packages/start/src/server/fetchEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,12 +32,12 @@ export function cloneEvent<T extends FetchEvent>(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) {
Expand Down

0 comments on commit 65c8ac0

Please sign in to comment.