Skip to content

Commit 1e99ffc

Browse files
authored
Remove redundant RSC fetch monkey patches (#603)
1 parent 861b817 commit 1e99ffc

4 files changed

Lines changed: 0 additions & 140 deletions

File tree

src/lib/rsc-route-normalization.test.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/lib/rsc-route-normalization.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/pages/_layout.tsx

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
import type { PropsWithChildren } from 'react'
22

3-
export const normalizeProxiedRscFetch = `
4-
(() => {
5-
if (window.__tempoNormalizeProxiedRscFetch) return;
6-
window.__tempoNormalizeProxiedRscFetch = true;
7-
const originalFetch = window.fetch.bind(window);
8-
window.fetch = (input, init) => {
9-
const url = typeof input === 'string'
10-
? input
11-
: input instanceof URL
12-
? input.toString()
13-
: input.url;
14-
const requestUrl = new URL(url, window.location.href);
15-
let rewritten = url;
16-
if (requestUrl.pathname.startsWith('/RSC/R/')) {
17-
const pathname = requestUrl.pathname
18-
.replace(/\\/RSC\\/R\\/developers\\.txt$/, '/RSC/R/_root.txt')
19-
.replace(/\\/RSC\\/R\\/developers\\//, '/RSC/R/');
20-
rewritten = new URL(
21-
pathname + requestUrl.search + requestUrl.hash,
22-
window.location.origin,
23-
).toString();
24-
}
25-
26-
if (rewritten === url) return originalFetch(input, init);
27-
if (typeof input === 'string' || input instanceof URL) return originalFetch(rewritten, init);
28-
29-
return originalFetch(new Request(rewritten, input), init);
30-
};
31-
})();
32-
`
33-
343
export default function Layout(
354
props: PropsWithChildren<{
365
path: string
@@ -46,8 +15,6 @@ export default function Layout(
4615
type="font/woff2"
4716
crossOrigin="anonymous"
4817
/>
49-
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: static bootstrap must run before the RSC client bundle. */}
50-
<script dangerouslySetInnerHTML={{ __html: normalizeProxiedRscFetch }} />
5118
{props.children}
5219
</>
5320
)

src/pages/docs/_layout.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import DocsHeader from '../../components/DocsHeader'
55
import DocsSectionNav from '../../components/DocsSectionNav'
66
import DocsSidebarDrawer from '../../components/DocsSidebarDrawer'
77
import { usePageSettled } from '../../lib/pageSettled'
8-
import { normalizeRscFetchUrl } from '../../lib/rsc-route-normalization'
98

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

2019
if (typeof window !== 'undefined') {
21-
const originalFetch = window.fetch.bind(window)
22-
window.fetch = (input, init) => {
23-
const url =
24-
typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url
25-
const rewritten = normalizeRscFetchUrl(url, window.location.href, window.location.origin)
26-
27-
if (rewritten === url) return originalFetch(input, init)
28-
if (typeof input === 'string' || input instanceof URL) return originalFetch(rewritten, init)
29-
30-
return originalFetch(new Request(rewritten, input), init)
31-
}
32-
3320
window.addEventListener('vite:preloadError', (event) => {
3421
const key = `vite:preloadError:${(event as unknown as CustomEvent).detail?.message}`
3522
if (!sessionStorage.getItem(key)) {

0 commit comments

Comments
 (0)