Skip to content
Merged
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
24 changes: 23 additions & 1 deletion packages/app/src/lib/mock-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,28 @@ function mockResponse(url: URL, method: string, init?: RequestInit): Response {
)
}

function normalizeStaticRscResponse(url: URL, response: Response): Response {
if (
!response.ok ||
!url.pathname.endsWith('.rsc') ||
response.headers.get('Content-Type')?.startsWith('text/x-component')
) {
return response
}

const headers = new Headers(response.headers)
headers.set('Content-Type', 'text/x-component')

// GitHub Pages serves unknown extensions as application/octet-stream.
// Shadowing the immutable header collection preserves the fetched response's
// URL and body, which vinext uses when deciding whether to navigate in-app.
Object.defineProperty(response, 'headers', {
configurable: true,
value: headers,
})
return response
}

/** Installs the browser-only API simulator used by the public GitHub Pages demo. */
export function installMockApi(): void {
if (installed || typeof window === 'undefined') return
Expand All @@ -676,7 +698,7 @@ export function installMockApi(): void {
) {
return mockResponse(url, method, init)
}
return nativeFetch(input, init)
return normalizeStaticRscResponse(url, await nativeFetch(input, init))
}
}

Expand Down
Loading