Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent erroneous route interception during lazy fetch #64692

Merged
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
4 changes: 3 additions & 1 deletion packages/next/src/client/components/layout-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { RedirectBoundary } from './redirect-boundary'
import { NotFoundBoundary } from './not-found-boundary'
import { getSegmentValue } from './router-reducer/reducers/get-segment-value'
import { createRouterCacheKey } from './router-reducer/create-router-cache-key'
import { hasInterceptionRouteInCurrentTree } from './router-reducer/reducers/has-interception-route-in-current-tree'

/**
* Add refetch marker to router state at the point of the current layout segment.
Expand Down Expand Up @@ -408,10 +409,11 @@ function InnerLayoutRouter({
*/
// TODO-APP: remove ''
const refetchTree = walkAddRefetch(['', ...segmentPath], fullTree)
const includeNextUrl = hasInterceptionRouteInCurrentTree(fullTree)
childNode.lazyData = lazyData = fetchServerResponse(
new URL(url, location.origin),
refetchTree,
context.nextUrl,
includeNextUrl ? context.nextUrl : null,
buildId
)
childNode.lazyDataResolved = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@ createNextDescribe(
})
})

it('should not trigger the intercepted route when lazy-fetching missing data', async () => {
const browser = await next.browser('/')

// trigger the interception page
await browser.elementByCss("[href='/detail-page']").click()

// we should see the intercepted page
expect(await browser.elementById('detail-title').text()).toBe(
'Detail Page (Intercepted)'
)

// refresh the page
await browser.refresh()

// we should see the detail page
expect(await browser.elementById('detail-title').text()).toBe(
'Detail Page (Non-Intercepted)'
)

// go back to the previous page
await browser.back()

// reload the page, which will cause the router to no longer have cache nodes
await browser.refresh()

// go forward, this will trigger a lazy fetch for the missing data, and should restore the detail page
await browser.forward()

expect(await browser.elementById('detail-title').text()).toBe(
'Detail Page (Non-Intercepted)'
)
})

describe.each([
{ basePath: '/refreshing', label: 'regular', withSearchParams: false },
{ basePath: '/refreshing', label: 'regular', withSearchParams: true },
Expand Down
Loading