Skip to content

Commit

Permalink
Merge branch 'canary' into wbinnssmith/hmr-log
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 14, 2023
2 parents 3567112 + a73abad commit 6afbdfe
Show file tree
Hide file tree
Showing 44 changed files with 1,085 additions and 479 deletions.
2 changes: 1 addition & 1 deletion examples/cms-keystonejs-embedded/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@keystone-next/fields": "^15.0.0",
"@keystone-next/keystone": "^25.0.0",
"@keystone-next/keystone": "^27.0.2",
"next": "10.2.2",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
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.4.20-canary.28"
"version": "13.4.20-canary.29"
}
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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "13.4.20-canary.28",
"@next/eslint-plugin-next": "13.4.20-canary.29",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"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.4.20-canary.28",
"version": "13.4.20-canary.29",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
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.4.20-canary.28",
"version": "13.4.20-canary.29",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs native",
Expand Down
7 changes: 6 additions & 1 deletion packages/next/navigation-types/compat/navigation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ declare module 'next/navigation' {
*
* If used from `pages/`, the hook will return `null`.
*/
export function useParams(): Record<string, string | string[]> | null
export function useParams<
T extends Record<string, string | string[]> = Record<
string,
string | string[]
>
>(): T | null
}
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.4.20-canary.28",
"version": "13.4.20-canary.29",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -90,7 +90,7 @@
]
},
"dependencies": {
"@next/env": "13.4.20-canary.28",
"@next/env": "13.4.20-canary.29",
"@swc/helpers": "0.5.1",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
Expand Down Expand Up @@ -145,11 +145,11 @@
"@mswjs/interceptors": "0.23.0",
"@napi-rs/cli": "2.16.2",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "13.4.20-canary.28",
"@next/polyfill-nomodule": "13.4.20-canary.28",
"@next/react-dev-overlay": "13.4.20-canary.28",
"@next/react-refresh-utils": "13.4.20-canary.28",
"@next/swc": "13.4.20-canary.28",
"@next/polyfill-module": "13.4.20-canary.29",
"@next/polyfill-nomodule": "13.4.20-canary.29",
"@next/react-dev-overlay": "13.4.20-canary.29",
"@next/react-refresh-utils": "13.4.20-canary.29",
"@next/swc": "13.4.20-canary.29",
"@opentelemetry/api": "1.4.1",
"@playwright/test": "^1.35.1",
"@segment/ajv-human-errors": "2.1.2",
Expand Down
102 changes: 50 additions & 52 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import loadCustomRoutes, {
normalizeRouteRegex,
Redirect,
Rewrite,
RouteHas,
RouteType,
} from '../lib/load-custom-routes'
import { getRedirectStatus, modifyRouteRegex } from '../lib/redirect-status'
Expand Down Expand Up @@ -130,6 +131,7 @@ import { flatReaddir } from '../lib/flat-readdir'
import { eventSwcPlugins } from '../telemetry/events/swc-plugins'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import {
ACTION,
NEXT_ROUTER_PREFETCH,
RSC,
RSC_CONTENT_TYPE_HEADER,
Expand Down Expand Up @@ -160,13 +162,15 @@ export type SsgRoute = {
dataRoute: string | null
initialStatus?: number
initialHeaders?: Record<string, string>
experimentalBypassFor?: RouteHas[]
}

export type DynamicSsgRoute = {
routeRegex: string
fallback: string | null | false
dataRoute: string | null
dataRouteRegex: string | null
experimentalBypassFor?: RouteHas[]
}

export type PrerenderManifest = {
Expand Down Expand Up @@ -1612,14 +1616,6 @@ export default async function build(
`Using edge runtime on a page currently disables static generation for that page`
)
} else {
// If a page has action and it is static, we need to
// change it to SSG to keep the worker created.
// TODO: This is a workaround for now, we should have a
// dedicated worker defined in a heuristic way.
const hasAction = entriesWithAction?.has(
'app' + originalAppPath
)

if (
workerResult.encodedPrerenderRoutes &&
workerResult.prerenderRoutes
Expand All @@ -1638,47 +1634,39 @@ export default async function build(

const appConfig = workerResult.appConfig || {}
if (appConfig.revalidate !== 0) {
if (hasAction) {
Log.warnOnce(
`Using server actions on a page currently disables static generation for that page`
const isDynamic = isDynamicRoute(page)
const hasGenerateStaticParams =
!!workerResult.prerenderRoutes?.length

if (
config.output === 'export' &&
isDynamic &&
!hasGenerateStaticParams
) {
throw new Error(
`Page "${page}" is missing "generateStaticParams()" so it cannot be used with "output: export" config.`
)
} else {
const isDynamic = isDynamicRoute(page)
const hasGenerateStaticParams =
!!workerResult.prerenderRoutes?.length

if (
config.output === 'export' &&
isDynamic &&
!hasGenerateStaticParams
) {
throw new Error(
`Page "${page}" is missing "generateStaticParams()" so it cannot be used with "output: export" config.`
)
}

if (
// Mark the app as static if:
// - It has no dynamic param
// - It doesn't have generateStaticParams but `dynamic` is set to
// `error` or `force-static`
!isDynamic
) {
appStaticPaths.set(originalAppPath, [page])
appStaticPathsEncoded.set(originalAppPath, [
page,
])
isStatic = true
} else if (
isDynamic &&
!hasGenerateStaticParams &&
(appConfig.dynamic === 'error' ||
appConfig.dynamic === 'force-static')
) {
appStaticPaths.set(originalAppPath, [])
appStaticPathsEncoded.set(originalAppPath, [])
isStatic = true
}
}

if (
// Mark the app as static if:
// - It has no dynamic param
// - It doesn't have generateStaticParams but `dynamic` is set to
// `error` or `force-static`
!isDynamic
) {
appStaticPaths.set(originalAppPath, [page])
appStaticPathsEncoded.set(originalAppPath, [page])
isStatic = true
} else if (
isDynamic &&
!hasGenerateStaticParams &&
(appConfig.dynamic === 'error' ||
appConfig.dynamic === 'force-static')
) {
appStaticPaths.set(originalAppPath, [])
appStaticPathsEncoded.set(originalAppPath, [])
isStatic = true
}
}

Expand Down Expand Up @@ -2681,6 +2669,17 @@ export default async function build(

const isRouteHandler = isAppRouteRoute(originalAppPath)

// this flag is used to selectively bypass the static cache and invoke the lambda directly
// to enable server actions on static routes
const bypassFor: RouteHas[] = [
{ type: 'header', key: ACTION },
{
type: 'header',
key: 'content-type',
value: 'multipart/form-data',
},
]

routes.forEach((route) => {
if (isDynamicRoute(page) && route === page) return
if (route === '/_not-found') return
Expand Down Expand Up @@ -2708,10 +2707,7 @@ export default async function build(
? null
: path.posix.join(`${normalizedRoute}.rsc`)

const routeMeta: {
initialStatus?: SsgRoute['initialStatus']
initialHeaders?: SsgRoute['initialHeaders']
} = {}
const routeMeta: Partial<SsgRoute> = {}

const exportRouteMeta: {
status?: number
Expand Down Expand Up @@ -2748,6 +2744,7 @@ export default async function build(

finalPrerenderRoutes[route] = {
...routeMeta,
experimentalBypassFor: bypassFor,
initialRevalidateSeconds: revalidate,
srcRoute: page,
dataRoute,
Expand All @@ -2771,6 +2768,7 @@ export default async function build(
// TODO: create a separate manifest to allow enforcing
// dynamicParams for non-static paths?
finalDynamicRoutes[page] = {
experimentalBypassFor: bypassFor,
routeRegex: normalizeRouteRegex(
getNamedRouteRegex(page, false).re.source
),
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/client/components/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ function getSelectedParams(
* Get the current parameters. For example useParams() on /dashboard/[team]
* where pathname is /dashboard/nextjs would return { team: 'nextjs' }
*/
export function useParams(): Params {
export function useParams<T extends Params = Params>(): T {
clientHookInServerComponentError('useParams')
const globalLayoutRouterContext = useContext(GlobalLayoutRouterContext)
if (!globalLayoutRouterContext) {
// This only happens in `pages`. Type is overwritten in navigation.d.ts
return null!
}
return getSelectedParams(globalLayoutRouterContext.tree)
return getSelectedParams(globalLayoutRouterContext.tree) as T
}

// TODO-APP: handle parallel routes
Expand Down
21 changes: 21 additions & 0 deletions packages/next/src/server/api-utils/get-cookie-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { NextApiRequestCookies } from '.'

/**
* Parse cookies from the `headers` of request
* @param req request object
*/

export function getCookieParser(headers: {
[key: string]: string | string[] | null | undefined
}): () => NextApiRequestCookies {
return function parseCookie(): NextApiRequestCookies {
const { cookie } = headers

if (!cookie) {
return {}
}

const { parse: parseCookieFn } = require('next/dist/compiled/cookie')
return parseCookieFn(Array.isArray(cookie) ? cookie.join('; ') : cookie)
}
}
Loading

0 comments on commit 6afbdfe

Please sign in to comment.