Skip to content

Commit

Permalink
Merge branch 'canary' into 04-17-prevent_erroneous_route_interception…
Browse files Browse the repository at this point in the history
…_during_lazy_fetch
  • Loading branch information
ztanner committed Apr 18, 2024
2 parents eee7203 + 134a59d commit ff22032
Show file tree
Hide file tree
Showing 31 changed files with 128 additions and 371 deletions.
188 changes: 74 additions & 114 deletions docs/02-app/01-building-your-application/09-authentication/index.mdx

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/next-swc/crates/next-core/src/next_server/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl ResolvePlugin for ExternalCjsModulesResolvePlugin {
way Node.js resolves modules is slightly different from the way Next.js \
resolves modules. Next.js was able to resolve it, while Node.js would not be \
able to.\nTry to remove this package from \
serverComponentsExtenalPackages.\nOr update the import side to use a \
serverComponentsExternalPackages.\nOr update the import side to use a \
compatible request that can be resolved by Node.js.",
);
};
Expand Down Expand Up @@ -486,7 +486,7 @@ impl Issue for UnableToExternalize {
StyledString::Text("Package ".to_string()),
StyledString::Code(package),
StyledString::Text(" (".to_string()),
StyledString::Code("serverComponentsExtenalPackages".to_string()),
StyledString::Code("serverComponentsExternalPackages".to_string()),
StyledString::Text(" or default list) can't be external".to_string()),
])
.cell())
Expand All @@ -510,7 +510,7 @@ impl Issue for UnableToExternalize {
StyledString::Text("The request ".to_string()),
StyledString::Code(self.request.to_string()),
StyledString::Text(" matches ".to_string()),
StyledString::Code("serverComponentsExtenalPackages".to_string()),
StyledString::Code("serverComponentsExternalPackages".to_string()),
StyledString::Text(
" (or the default list), but it can't be external:".to_string(),
),
Expand Down
4 changes: 1 addition & 3 deletions packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export function createEmptyCacheNode(): CacheNode {
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
error: null,
}
}

Expand Down Expand Up @@ -627,9 +626,8 @@ function Router({
// Provided in AppTreeContext to ensure it can be overwritten in layout-router
url: canonicalUrl,
loading: cache.loading,
error: cache.error,
}
}, [cache.parallelRoutes, tree, canonicalUrl, cache.loading, cache.error])
}, [cache.parallelRoutes, tree, canonicalUrl, cache.loading])

const globalLayoutRouterContext = useMemo(() => {
return {
Expand Down
17 changes: 11 additions & 6 deletions packages/next/src/client/components/layout-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
FlightSegmentPath,
Segment,
} from '../../server/app-render/types'
import type { ErrorComponent } from './error-boundary'
import type { FocusAndScrollRef } from './router-reducer/router-reducer-types'

import React, {
Expand Down Expand Up @@ -358,7 +359,6 @@ function InnerLayoutRouter({
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
error: null,
}

/**
Expand Down Expand Up @@ -455,7 +455,6 @@ function InnerLayoutRouter({
// TODO-APP: overriding of url for parallel routes
url: url,
loading: childNode.loading,
error: childNode.error,
}}
>
{resolvedRsc}
Expand Down Expand Up @@ -510,6 +509,9 @@ function LoadingBoundary({
export default function OuterLayoutRouter({
parallelRouterKey,
segmentPath,
error,
errorStyles,
errorScripts,
templateStyles,
templateScripts,
template,
Expand All @@ -519,6 +521,9 @@ export default function OuterLayoutRouter({
}: {
parallelRouterKey: string
segmentPath: FlightSegmentPath
error: ErrorComponent | undefined
errorStyles: React.ReactNode | undefined
errorScripts: React.ReactNode | undefined
templateStyles: React.ReactNode | undefined
templateScripts: React.ReactNode | undefined
template: React.ReactNode
Expand All @@ -531,7 +536,7 @@ export default function OuterLayoutRouter({
throw new Error('invariant expected layout router to be mounted')
}

const { childNodes, tree, url, loading, error } = context
const { childNodes, tree, url, loading } = context

// Get the current parallelRouter cache node
let childNodesForParallelRouter = childNodes.get(parallelRouterKey)
Expand Down Expand Up @@ -577,9 +582,9 @@ export default function OuterLayoutRouter({
value={
<ScrollAndFocusHandler segmentPath={segmentPath}>
<ErrorBoundary
errorComponent={error?.[0]}
errorStyles={error?.[1]}
errorScripts={error?.[2]}
errorComponent={error}
errorStyles={errorStyles}
errorScripts={errorScripts}
>
<LoadingBoundary
hasLoading={Boolean(loading)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('clearCacheNodeDataForSegmentPath', () => {
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
error: null,
}
const existingCache: CacheNode = {
lazyData: null,
Expand All @@ -31,7 +30,6 @@ describe('clearCacheNodeDataForSegmentPath', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand All @@ -46,7 +44,6 @@ describe('clearCacheNodeDataForSegmentPath', () => {
head: null,
prefetchHead: null,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand All @@ -62,7 +59,6 @@ describe('clearCacheNodeDataForSegmentPath', () => {
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
error: null,
},
],
]),
Expand All @@ -79,23 +75,20 @@ describe('clearCacheNodeDataForSegmentPath', () => {

expect(cache).toMatchInlineSnapshot(`
{
"error": null,
"head": null,
"lazyData": null,
"lazyDataResolved": false,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
"error": null,
"head": null,
"lazyData": null,
"lazyDataResolved": false,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"" => {
"error": null,
"head": null,
"lazyData": null,
"lazyDataResolved": false,
Expand All @@ -116,7 +109,6 @@ describe('clearCacheNodeDataForSegmentPath', () => {
</React.Fragment>,
},
"dashboard" => {
"error": null,
"head": null,
"lazyData": null,
"lazyDataResolved": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function clearCacheNodeDataForSegmentPath(
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
error: null,
})
}
return
Expand All @@ -62,7 +61,6 @@ export function clearCacheNodeDataForSegmentPath(
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
error: null,
})
}
return
Expand All @@ -78,7 +76,6 @@ export function clearCacheNodeDataForSegmentPath(
parallelRoutes: new Map(childCacheNode.parallelRoutes),
lazyDataResolved: childCacheNode.lazyDataResolved,
loading: childCacheNode.loading,
error: childCacheNode.error,
} as CacheNode
childSegmentMap.set(cacheKey, childCacheNode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('createInitialRouterState', () => {
buildId,
initialTree,
initialCanonicalUrl,
initialSeedData: ['', {}, children, null, null],
initialSeedData: ['', {}, children, null],
initialParallelRoutes,
location: new URL('/linking', 'https://localhost') as any,
initialHead: <title>Test</title>,
Expand All @@ -48,7 +48,7 @@ describe('createInitialRouterState', () => {
buildId,
initialTree,
initialCanonicalUrl,
initialSeedData: ['', {}, children, null, null],
initialSeedData: ['', {}, children, null],
initialParallelRoutes,
location: new URL('/linking', 'https://localhost') as any,
initialHead: <title>Test</title>,
Expand All @@ -62,7 +62,6 @@ describe('createInitialRouterState', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand All @@ -82,7 +81,6 @@ describe('createInitialRouterState', () => {
prefetchRsc: null,
parallelRoutes: new Map(),
loading: null,
error: null,
head: <title>Test</title>,
prefetchHead: null,
lazyDataResolved: false,
Expand All @@ -98,7 +96,6 @@ describe('createInitialRouterState', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
},
],
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function createInitialRouterState({
parallelRoutes: isServer ? new Map() : initialParallelRoutes,
lazyDataResolved: false,
loading: initialSeedData[3],
error: initialSeedData[4],
}

const canonicalUrl =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
loading: null,
error: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
}
Expand All @@ -45,7 +44,6 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand All @@ -60,7 +58,6 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand All @@ -75,7 +72,6 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map(),
},
],
Expand Down Expand Up @@ -108,7 +104,6 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand All @@ -123,7 +118,6 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand All @@ -139,7 +133,6 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchHead: null,
lazyDataResolved: false,
loading: null,
error: null,
parallelRoutes: new Map(),
},
],
Expand All @@ -151,7 +144,6 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
loading: null,
error: null,
parallelRoutes: new Map([
[
'children',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ export function fillCacheWithNewSubTreeData(
const seedData: CacheNodeSeedData = flightDataPath[3]
const rsc = seedData[2]
const loading = seedData[3]
const error = seedData[4]
childCacheNode = {
lazyData: null,
rsc,
prefetchRsc: null,
head: null,
prefetchHead: null,
loading,
error,
// Ensure segments other than the one we got data for are preserved.
parallelRoutes: existingChildCacheNode
? new Map(existingChildCacheNode.parallelRoutes)
Expand Down Expand Up @@ -103,7 +101,6 @@ export function fillCacheWithNewSubTreeData(
parallelRoutes: new Map(childCacheNode.parallelRoutes),
lazyDataResolved: false,
loading: childCacheNode.loading,
error: childCacheNode.error,
} as CacheNode
childSegmentMap.set(cacheKey, childCacheNode)
}
Expand Down
Loading

0 comments on commit ff22032

Please sign in to comment.