Skip to content

Commit

Permalink
Temporarily disable prefetch in new router (vercel#41086)
Browse files Browse the repository at this point in the history
Co-authored-by: Balázs Orbán <info@balazsorban.com>
  • Loading branch information
2 people authored and BowlingX committed Oct 5, 2022
1 parent d35a27e commit 9785d41
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
58 changes: 28 additions & 30 deletions packages/next/client/components/app-router.client.tsx
Expand Up @@ -15,7 +15,7 @@ import type {
import type { FlightRouterState, FlightData } from '../../server/app-render'
import {
ACTION_NAVIGATE,
ACTION_PREFETCH,
// ACTION_PREFETCH,
ACTION_RELOAD,
ACTION_RESTORE,
ACTION_SERVER_PATCH,
Expand Down Expand Up @@ -97,7 +97,7 @@ function ErrorOverlay({ children }: PropsWithChildren<{}>): ReactElement {
let initialParallelRoutes: CacheNode['parallelRoutes'] =
typeof window === 'undefined' ? null! : new Map()

const prefetched = new Set<string>()
// const prefetched = new Set<string>()

/**
* The global router that wraps the application components.
Expand Down Expand Up @@ -208,34 +208,32 @@ export default function AppRouter({

const routerInstance: AppRouterInstance = {
// TODO-APP: implement prefetching of flight
prefetch: async (href) => {
prefetch: async (_href) => {
// If prefetch has already been triggered, don't trigger it again.
if (prefetched.has(href)) {
return
}

prefetched.add(href)
const url = new URL(href, location.origin)

try {
// TODO-APP: handle case where history.state is not the new router history entry
const serverResponse = await fetchServerResponse(
url,
// initialTree is used when history.state.tree is missing because the history state is set in `useEffect` below, it being missing means this is the hydration case.
window.history.state?.tree || initialTree,
true
)
// @ts-ignore startTransition exists
React.startTransition(() => {
dispatch({
type: ACTION_PREFETCH,
url,
serverResponse,
})
})
} catch (err) {
console.error('PREFETCH ERROR', err)
}
// if (prefetched.has(href)) {
// return
// }
// prefetched.add(href)
// const url = new URL(href, location.origin)
// try {
// // TODO-APP: handle case where history.state is not the new router history entry
// const serverResponse = await fetchServerResponse(
// url,
// // initialTree is used when history.state.tree is missing because the history state is set in `useEffect` below, it being missing means this is the hydration case.
// window.history.state?.tree || initialTree,
// true
// )
// // @ts-ignore startTransition exists
// React.startTransition(() => {
// dispatch({
// type: ACTION_PREFETCH,
// url,
// serverResponse,
// })
// })
// } catch (err) {
// console.error('PREFETCH ERROR', err)
// }
},
replace: (href, options = {}) => {
// @ts-ignore startTransition exists
Expand Down Expand Up @@ -268,7 +266,7 @@ export default function AppRouter({
}

return routerInstance
}, [dispatch, initialTree])
}, [dispatch /*, initialTree*/])

useEffect(() => {
// When mpaNavigation flag is set do a hard navigation to the new url.
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/app-dir/index.test.ts
Expand Up @@ -418,7 +418,8 @@ describe('app dir', () => {
}
})

it('should soft push', async () => {
// TODO-APP: Re-enable this test.
it.skip('should soft push', async () => {
const browser = await webdriver(next.url, '/link-soft-push')

try {
Expand Down

0 comments on commit 9785d41

Please sign in to comment.