Skip to content
Merged
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
84 changes: 0 additions & 84 deletions src/lib/rsc-route-normalization.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/lib/rsc-route-normalization.ts

This file was deleted.

33 changes: 0 additions & 33 deletions src/pages/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
import type { PropsWithChildren } from 'react'

export const normalizeProxiedRscFetch = `
(() => {
if (window.__tempoNormalizeProxiedRscFetch) return;
window.__tempoNormalizeProxiedRscFetch = true;
const originalFetch = window.fetch.bind(window);
window.fetch = (input, init) => {
const url = typeof input === 'string'
? input
: input instanceof URL
? input.toString()
: input.url;
const requestUrl = new URL(url, window.location.href);
let rewritten = url;
if (requestUrl.pathname.startsWith('/RSC/R/')) {
const pathname = requestUrl.pathname
.replace(/\\/RSC\\/R\\/developers\\.txt$/, '/RSC/R/_root.txt')
.replace(/\\/RSC\\/R\\/developers\\//, '/RSC/R/');
rewritten = new URL(
pathname + requestUrl.search + requestUrl.hash,
window.location.origin,
).toString();
}

if (rewritten === url) return originalFetch(input, init);
if (typeof input === 'string' || input instanceof URL) return originalFetch(rewritten, init);

return originalFetch(new Request(rewritten, input), init);
};
})();
`

export default function Layout(
props: PropsWithChildren<{
path: string
Expand All @@ -46,8 +15,6 @@ export default function Layout(
type="font/woff2"
crossOrigin="anonymous"
/>
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: static bootstrap must run before the RSC client bundle. */}
<script dangerouslySetInnerHTML={{ __html: normalizeProxiedRscFetch }} />
{props.children}
</>
)
Expand Down
13 changes: 0 additions & 13 deletions src/pages/docs/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import DocsHeader from '../../components/DocsHeader'
import DocsSectionNav from '../../components/DocsSectionNav'
import DocsSidebarDrawer from '../../components/DocsSidebarDrawer'
import { usePageSettled } from '../../lib/pageSettled'
import { normalizeRscFetchUrl } from '../../lib/rsc-route-normalization'

const Analytics = lazy(() =>
import('@vercel/analytics/react').then((module) => ({ default: module.Analytics })),
Expand All @@ -18,18 +17,6 @@ const GoogleAnalytics = lazy(() => import('../../components/GoogleAnalytics'))
const PostHogSetup = lazy(() => import('../../components/PostHogSetup'))

if (typeof window !== 'undefined') {
const originalFetch = window.fetch.bind(window)
window.fetch = (input, init) => {
const url =
typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url
const rewritten = normalizeRscFetchUrl(url, window.location.href, window.location.origin)

if (rewritten === url) return originalFetch(input, init)
if (typeof input === 'string' || input instanceof URL) return originalFetch(rewritten, init)

return originalFetch(new Request(rewritten, input), init)
}

window.addEventListener('vite:preloadError', (event) => {
const key = `vite:preloadError:${(event as unknown as CustomEvent).detail?.message}`
if (!sessionStorage.getItem(key)) {
Expand Down
Loading