Skip to content

Commit

Permalink
Merge branch 'canary' into refactor/test-cna
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Apr 1, 2024
2 parents 658357d + e4a831c commit 76e77e8
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 37 deletions.
14 changes: 11 additions & 3 deletions packages/next/src/build/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ export function runCompiler(
{
runWebpackSpan,
inputFileSystem,
}: { runWebpackSpan: Span; inputFileSystem?: any }
): Promise<[result: CompilerResult, inputFileSystem?: any]> {
}: {
runWebpackSpan: Span
inputFileSystem?: webpack.Compiler['inputFileSystem']
}
): Promise<
[
result: CompilerResult,
inputFileSystem?: webpack.Compiler['inputFileSystem']
]
> {
return new Promise((resolve, reject) => {
const compiler = webpack(config) as unknown as webpack.Compiler
const compiler = webpack(config)
// Ensure we use the previous inputFileSystem
if (inputFileSystem) {
compiler.inputFileSystem = inputFileSystem
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/build/normalize-catchall-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ describe('normalizeCatchallRoutes', () => {
})
})

it('should only match optional catch-all paths to the "index" of a segment', () => {
// TODO-APP: Enable this test once support for optional catch-all slots is added.
it.skip('should only match optional catch-all paths to the "index" of a segment', () => {
const appPaths = {
'/': ['/page'],
'/[[...catchAll]]': ['/@slot/[[...catchAll]]/page'],
Expand Down
18 changes: 5 additions & 13 deletions packages/next/src/build/normalize-catchall-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ export function normalizeCatchAllRoutes(
// check if the appPath could match the catch-all
appPath.startsWith(normalizedCatchAllRouteBasePath) &&
// check if there's not already a slot value that could match the catch-all
!appPaths[appPath].some((path) =>
hasMatchedSlots(path, catchAllRoute)
) &&
// check if appPath is a catch-all OR is not more specific than the catch-all
(isCatchAllRoute(appPath) || !isMoreSpecific(appPath, catchAllRoute))
!appPaths[appPath].some((path) => hasMatchedSlots(path, catchAllRoute))
) {
// optional catch-all routes are not currently supported, but leaving this logic in place
// for when they are eventually supported.
if (isOptionalCatchAll(catchAllRoute)) {
// optional catch-all routes should match both the root segment and any segment after it
// for example, `/[[...slug]]` should match `/` and `/foo` and `/foo/bar`
Expand Down Expand Up @@ -90,7 +88,8 @@ function isMatchableSlot(segment: string): boolean {
const catchAllRouteRegex = /\[?\[\.\.\./

function isCatchAllRoute(pathname: string): boolean {
return isOptionalCatchAll(pathname) || isCatchAll(pathname)
// Optional catch-all slots are not currently supported, and as such they are not considered when checking for match compatability.
return !isOptionalCatchAll(pathname) && isCatchAll(pathname)
}

function isOptionalCatchAll(pathname: string): boolean {
Expand All @@ -100,10 +99,3 @@ function isOptionalCatchAll(pathname: string): boolean {
function isCatchAll(pathname: string): boolean {
return pathname.includes('[...')
}

// test to see if a path is more specific than a catch-all route
function isMoreSpecific(pathname: string, catchAllRoute: string): boolean {
const pathnameDepth = pathname.split('/').length
const catchAllRouteDepth = catchAllRoute.split('/').length - 1
return pathnameDepth > catchAllRouteDepth
}
28 changes: 12 additions & 16 deletions packages/next/src/build/webpack-build/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export async function webpackBuildImpl(
| UnwrapPromise<ReturnType<typeof runCompiler>>[0]
| null = null

let inputFileSystem: any
let inputFileSystem: webpack.Compiler['inputFileSystem'] | undefined

if (!compilerName || compilerName === 'server') {
debug('starting server compiler')
Expand Down Expand Up @@ -246,23 +246,19 @@ export async function webpackBuildImpl(
}
}

inputFileSystem.purge()
inputFileSystem?.purge?.()

result = {
warnings: ([] as any[])
.concat(
clientResult?.warnings,
serverResult?.warnings,
edgeServerResult?.warnings
)
.filter(nonNullable),
errors: ([] as any[])
.concat(
clientResult?.errors,
serverResult?.errors,
edgeServerResult?.errors
)
.filter(nonNullable),
warnings: [
...(clientResult?.warnings ?? []),
...(serverResult?.warnings ?? []),
...(edgeServerResult?.warnings ?? []),
].filter(nonNullable),
errors: [
...(clientResult?.errors ?? []),
...(serverResult?.errors ?? []),
...(edgeServerResult?.errors ?? []),
].filter(nonNullable),
stats: [
clientResult?.stats,
serverResult?.stats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,9 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
return segments.length ? segments[0] : null
}

const getResolve = (options: any) => {
const getResolve = (
options: Parameters<typeof resolver.withOptions>[0]
) => {
const curResolver = resolver.withOptions(options)

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type InternalLinkProps = {
/**
* Prefetch the page in the background.
* Any `<Link />` that is in the viewport (initially or through scroll) will be preloaded.
* Prefetch can be disabled by passing `prefetch={false}`. When `prefetch` is set to `false`, prefetching will still occur on hover. Pages using [Static Generation](/docs/basic-features/data-fetching/get-static-props.md) will preload `JSON` files with the data for faster page transitions. Prefetching is only enabled in production.
* Prefetch can be disabled by passing `prefetch={false}`. When `prefetch` is set to `false`, prefetching will still occur on hover in pages router but not in app router. Pages using [Static Generation](/docs/basic-features/data-fetching/get-static-props.md) will preload `JSON` files with the data for faster page transitions. Prefetching is only enabled in production.
*
* @defaultValue `true`
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/export/routes/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function exportPages(
const validateAmp = async (
rawAmpHtml: string,
ampPageName: string,
validatorPath?: string
validatorPath: string | undefined
) => {
const validator = await AmpHtmlValidator.getInstance(validatorPath)
const result = validator.validateString(rawAmpHtml)
Expand Down Expand Up @@ -170,7 +170,7 @@ export async function exportPages(
? ampRenderResult.toUnchunkedString()
: ''
if (!renderOpts.ampSkipValidation) {
await validateAmp(ampHtml, page + '?amp=1')
await validateAmp(ampHtml, page + '?amp=1', ampValidatorPath)
}

await fileWriter(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Link from 'next/link'

export default function Page() {
return (
<div>
<h1>Modal</h1>
<ul>
<li>
<Link href="/u/foobar/l">Profile Link</Link>
</li>
<li>
<Link href="/trending">Trending Link</Link>
</li>
</ul>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function CatchAll() {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Page({
params: { productId },
}: {
params: { productId: string }
}) {
return <h1>{productId}</h1>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ReactNode } from 'react'

const RootLayout = ({
children,
modal,
}: {
children: ReactNode
modal: ReactNode
}) => {
return (
<html lang="en">
<body>
{children}
{modal}
</body>
</html>
)
}

export default RootLayout
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function Page() {
return (
<div>
<Link href="/comments/some-text">Open Modal</Link>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function TrendingPage() {
return <h1>Trending</h1>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <h1>Profile</h1>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'

describe('parallel-routes-catchall-specificity', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should match the catch-all route when navigating from a page with a similar path depth as the previously matched slot', async () => {
const browser = await next.browser('/')

await browser.elementByCss('[href="/comments/some-text"]').click()

await browser.waitForElementByCss('h1')

// we're matching @modal/(...comments)/[productId]
expect(await browser.elementByCss('h1').text()).toBe('Modal')

await browser.elementByCss('[href="/u/foobar/l"]').click()

// we're now matching @modal/[...catchAll]
await retry(async () => {
expect(await browser.elementByCss('h1').text()).toBe('Profile')
})

await browser.back()

await browser.elementByCss('[href="/trending"]').click()

await retry(async () => {
expect(await browser.elementByCss('h1').text()).toBe('Trending')
})
})
})
9 changes: 9 additions & 0 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,15 @@
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/parallel-routes-catchall-specificity/parallel-routes-catchall-specificity.test.ts": {
"passed": [],
"failed": [
"parallel-routes-catchall-specificity should match the catch-all route when navigating from a page with a similar path depth as the previously matched slot"
],
"pending": [],
"flakey": [],
"runtimeError": false
},
"test/e2e/app-dir/parallel-routes-catchall/parallel-routes-catchall.test.ts": {
"passed": [
"parallel-routes-catchall should match correctly when defining an explicit page & slot",
Expand Down

0 comments on commit 76e77e8

Please sign in to comment.