Skip to content

Commit

Permalink
Merge branch 'canary' into update/separate-route-resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Apr 2, 2023
2 parents 94ca08e + fae9441 commit 38f738b
Show file tree
Hide file tree
Showing 29 changed files with 136 additions and 67 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "13.2.5-canary.25"
"version": "13.2.5-canary.26"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -12,7 +12,7 @@
"test-pack": "cd ../../ && pnpm test-pack eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "13.2.5-canary.25",
"@next/eslint-plugin-next": "13.2.5-canary.26",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.42.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"description": "ESLint plugin for NextJS.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
26 changes: 18 additions & 8 deletions packages/next-swc/crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ where
}
};

let mut modularize_imports_config = match &opts.modularize_imports {
Some(config) => config.clone(),
None => turbo_binding::swc::custom_transform::modularize_imports::Config {
packages: std::collections::HashMap::new(),
},
};
modularize_imports_config.packages.insert(
"next/server".to_string(),
turbo_binding::swc::custom_transform::modularize_imports::PackageConfig {
transform: "next/dist/server/web/exports/{{ kebabCase member }}".to_string(),
prevent_full_import: false,
skip_default_conversion: false,
},
);

chain!(
disallow_re_export_all_in_page::disallow_re_export_all_in_page(opts.is_page_file),
match &opts.server_components {
Expand Down Expand Up @@ -244,14 +259,9 @@ where
}
})
.unwrap_or_else(|| Either::Right(noop())),
match &opts.modularize_imports {
Some(config) => Either::Left(
turbo_binding::swc::custom_transform::modularize_imports::modularize_imports(
config.clone()
)
),
None => Either::Right(noop()),
},
turbo_binding::swc::custom_transform::modularize_imports::modularize_imports(
modularize_imports_config
),
match &opts.font_loaders {
Some(config) => Either::Left(next_font_loaders(config.clone())),
None => Either::Right(noop()),
Expand Down
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/src/router_source.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::{anyhow, Context, Result};
use futures::stream::StreamExt;
use indexmap::IndexSet;
use turbo_binding::turbopack::{
core::{
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"private": true,
"scripts": {
"clean": "rm -rf ./native/*",
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -82,7 +82,7 @@
]
},
"dependencies": {
"@next/env": "13.2.5-canary.25",
"@next/env": "13.2.5-canary.26",
"@swc/helpers": "0.4.14",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
Expand Down Expand Up @@ -139,11 +139,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "2.14.7",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "13.2.5-canary.25",
"@next/polyfill-nomodule": "13.2.5-canary.25",
"@next/react-dev-overlay": "13.2.5-canary.25",
"@next/react-refresh-utils": "13.2.5-canary.25",
"@next/swc": "13.2.5-canary.25",
"@next/polyfill-module": "13.2.5-canary.26",
"@next/polyfill-nomodule": "13.2.5-canary.26",
"@next/react-dev-overlay": "13.2.5-canary.26",
"@next/react-refresh-utils": "13.2.5-canary.26",
"@next/swc": "13.2.5-canary.26",
"@opentelemetry/api": "1.4.1",
"@segment/ajv-human-errors": "2.1.2",
"@taskr/clear": "1.1.0",
Expand Down
10 changes: 1 addition & 9 deletions packages/next/src/build/swc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ function getBaseSWCOptions({
.filter(Array.isArray)
.map(([name, options]: any) => [require.resolve(name), options])

// Use modularized imports for next/server to ensure treeshaking.
// This prevents ImageResponse related assets from being bundled when not used.
// TODO: move it into next-swc
const modularizeImports = nextConfig?.modularizeImports || {}
modularizeImports['next/server'] = {
transform: 'next/dist/server/web/exports/{{ kebabCase member }}',
}

return {
jsc: {
...(resolvedBaseUrl && paths
Expand Down Expand Up @@ -123,7 +115,7 @@ function getBaseSWCOptions({
reactRemoveProperties: jest
? false
: nextConfig?.compiler?.reactRemoveProperties,
modularizeImports,
modularizeImports: nextConfig?.modularizeImports,
relay: nextConfig?.compiler?.relay,
// Always transform styled-jsx and error when `client-only` condition is triggered
styledJsx: true,
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/build/webpack/plugins/next-types-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,14 @@ type FirstArg<T extends Function> = T extends (...args: [infer T, any]) => any ?
type SecondArg<T extends Function> = T extends (...args: [any, infer T]) => any ? unknown extends T ? any : T : never
type MaybeField<T, K extends string> = T extends { [k in K]: infer G } ? G extends Function ? G : never : never
type ParamCheck<T> = {
${
options.type === 'route'
? `type ParamCheck<T> = {
__tag__: string
__param_position__: string
__param_type__: T
}`
: ''
}
function checkFields<_ extends { [k in keyof any]: never }>() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function isWhitespace(char: string) {
return char === ' ' || char === '\n'
// Returns true if the given character is a whitespace character, false otherwise.
function isWhitespace(char: string): boolean {
return char === ' ' || char === '\n' || char === '\t' || char === '\r'
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { ReadonlyReducerState } from './router-reducer-types'
export function applyFlightData(
state: ReadonlyReducerState,
cache: CacheNode,
flightDataPath: FlightDataPath
flightDataPath: FlightDataPath,
wasPrefetched?: boolean
): boolean {
// The one before last item is the router state tree patch
const [treePatch, subTreeData, head] = flightDataPath.slice(-3)
Expand All @@ -20,7 +21,13 @@ export function applyFlightData(
if (flightDataPath.length === 3) {
cache.status = CacheStates.READY
cache.subTreeData = subTreeData
fillLazyItemsTillLeafWithHead(cache, state.cache, treePatch, head)
fillLazyItemsTillLeafWithHead(
cache,
state.cache,
treePatch,
head,
wasPrefetched
)
} else {
// Copy subTreeData for the root node of the cache.
cache.status = CacheStates.READY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export function fillLazyItemsTillLeafWithHead(
newCache: CacheNode,
existingCache: CacheNode | undefined,
routerState: FlightRouterState,
head: React.ReactNode
head: React.ReactNode,
wasPrefetched?: boolean
): void {
const isLastSegment = Object.keys(routerState[1]).length === 0
if (isLastSegment) {
Expand All @@ -26,19 +27,29 @@ export function fillLazyItemsTillLeafWithHead(
if (existingParallelRoutesCacheNode) {
let parallelRouteCacheNode = new Map(existingParallelRoutesCacheNode)
const existingCacheNode = parallelRouteCacheNode.get(cacheKey)
parallelRouteCacheNode.delete(cacheKey)
const newCacheNode: CacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
}
const newCacheNode: CacheNode =
wasPrefetched && existingCacheNode
? ({
status: existingCacheNode.status,
data: existingCacheNode.data,
subTreeData: existingCacheNode.subTreeData,
parallelRoutes: new Map(existingCacheNode.parallelRoutes),
} as CacheNode)
: {
status: CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
}
// Overrides the cache key with the new cache node.
parallelRouteCacheNode.set(cacheKey, newCacheNode)
// Traverse deeper to apply the head / fill lazy items till the head.
fillLazyItemsTillLeafWithHead(
newCacheNode,
undefined,
wasPrefetched ? existingCacheNode : undefined,
parallelRouteState,
head
head,
wasPrefetched
)

newCache.parallelRoutes.set(key, parallelRouteCacheNode)
Expand All @@ -64,7 +75,8 @@ export function fillLazyItemsTillLeafWithHead(
newCacheNode,
undefined,
parallelRouteState,
head
head,
wasPrefetched
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function navigateReducer(
return handleExternalUrl(state, mutable, href, pendingPush)
}

const applied = applyFlightData(state, cache, flightDataPath)
const applied = applyFlightData(state, cache, flightDataPath, true)

const hardNavigate = shouldHardNavigate(
// TODO-APP: remove ''
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "13.2.5-canary.25",
"version": "13.2.5-canary.26",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/e2e/app-dir/app-prefetch/app/static-page/page.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import Link from 'next/link'

export default async function Page() {
return (
<>
<p id="static-page">Static Page</p>
<p>
<Link href="/" id="to-home">
To home
</Link>
</p>
</>
)
}

0 comments on commit 38f738b

Please sign in to comment.