Skip to content

Commit

Permalink
Merge branch 'canary' into kdy1/issue-source
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Nov 15, 2023
2 parents fa57143 + 52e8c4d commit aa629fd
Show file tree
Hide file tree
Showing 37 changed files with 276 additions and 191 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": "14.0.3-canary.7"
"version": "14.0.3-canary.8"
}
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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"@next/eslint-plugin-next": "14.0.3-canary.8",
"@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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"description": "ESLint plugin for Next.js.",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
15 changes: 13 additions & 2 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub struct ExperimentalConfig {
pub optimize_css: Option<serde_json::Value>,
pub next_script_workers: Option<bool>,
pub web_vitals_attribution: Option<Vec<String>>,
pub server_actions: Option<ServerActions>,
pub server_actions: Option<ServerActionsOrLegacyBool>,
pub sri: Option<SubResourceIntegrity>,

// ---
Expand Down Expand Up @@ -511,7 +511,18 @@ pub struct SubResourceIntegrity {
pub algorithm: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs)]
#[serde(untagged)]
pub enum ServerActionsOrLegacyBool {
/// The current way to configure server actions sub behaviors.
ServerActionsConfig(ServerActions),

/// The legacy way to disable server actions. This is no longer used, server
/// actions is always enabled.
LegacyBool(bool),
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, TraceRawVcs)]
#[serde(rename_all = "camelCase")]
pub struct ServerActions {
/// Allows adjusting body parser size limit for server actions.
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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs 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": "14.0.3-canary.7",
"version": "14.0.3-canary.8",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -92,7 +92,7 @@
]
},
"dependencies": {
"@next/env": "14.0.3-canary.7",
"@next/env": "14.0.3-canary.8",
"@swc/helpers": "0.5.2",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
Expand Down Expand Up @@ -146,11 +146,11 @@
"@mswjs/interceptors": "0.23.0",
"@napi-rs/cli": "2.16.2",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "14.0.3-canary.7",
"@next/polyfill-nomodule": "14.0.3-canary.7",
"@next/react-dev-overlay": "14.0.3-canary.7",
"@next/react-refresh-utils": "14.0.3-canary.7",
"@next/swc": "14.0.3-canary.7",
"@next/polyfill-module": "14.0.3-canary.8",
"@next/polyfill-nomodule": "14.0.3-canary.8",
"@next/react-dev-overlay": "14.0.3-canary.8",
"@next/react-refresh-utils": "14.0.3-canary.8",
"@next/swc": "14.0.3-canary.8",
"@opentelemetry/api": "1.6.0",
"@playwright/test": "^1.35.1",
"@taskr/clear": "1.1.0",
Expand Down
22 changes: 9 additions & 13 deletions packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
PrefetchKind,
} from './router-reducer/router-reducer-types'
import type {
PushRef,
AppRouterState,
ReducerActions,
RouterChangeByServerResponse,
RouterNavigate,
Expand All @@ -49,6 +49,7 @@ import {
import {
useReducerWithReduxDevtools,
useUnwrapState,
type ReduxDevtoolsSyncFn,
} from './use-reducer-with-devtools'
import { ErrorBoundary } from './error-boundary'
import { createInitialRouterState } from './router-reducer/create-initial-router-state'
Expand Down Expand Up @@ -110,17 +111,14 @@ function isExternalURL(url: URL) {
}

function HistoryUpdater({
tree,
pushRef,
canonicalUrl,
appRouterState,
sync,
}: {
tree: FlightRouterState
pushRef: PushRef
canonicalUrl: string
sync: () => void
appRouterState: AppRouterState
sync: ReduxDevtoolsSyncFn
}) {
useInsertionEffect(() => {
const { tree, pushRef, canonicalUrl } = appRouterState
const historyState = {
...(process.env.__NEXT_WINDOW_HISTORY_SUPPORT &&
pushRef.preserveCustomHistoryState
Expand Down Expand Up @@ -148,8 +146,8 @@ function HistoryUpdater({
originalReplaceState(historyState, '', canonicalUrl)
}
}
sync()
}, [tree, pushRef, canonicalUrl, sync])
sync(appRouterState)
}, [appRouterState, sync])
return null
}

Expand Down Expand Up @@ -589,9 +587,7 @@ function Router({
return (
<>
<HistoryUpdater
tree={tree}
pushRef={pushRef}
canonicalUrl={canonicalUrl}
appRouterState={useUnwrapState(reducerState)}
sync={sync}
/>
<PathnameContext.Provider value={pathname}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,14 @@ function processMessage(
})
)

if (!process.env.TURBOPACK) {
const isHotUpdate =
obj.action !== HMR_ACTIONS_SENT_TO_BROWSER.SYNC &&
(!window.__NEXT_DATA__ || window.__NEXT_DATA__.page !== '/_error') &&
isUpdateAvailable()

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
handleHotUpdate()
}
const isHotUpdate =
obj.action !== HMR_ACTIONS_SENT_TO_BROWSER.SYNC &&
(!window.__NEXT_DATA__ || window.__NEXT_DATA__.page !== '/_error') &&
isUpdateAvailable()

// Attempt to apply hot updates or reload.
if (isHotUpdate) {
handleHotUpdate()
}
return
}
Expand All @@ -370,6 +368,13 @@ function processMessage(
dispatcher.onRefresh()
})

if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB()
self.__NEXT_HMR_CB = null
}
}

return
}
case HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE: {
Expand Down Expand Up @@ -444,16 +449,6 @@ export default function HotReload({
}
}, [dispatch])

useEffect(() => {
if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB()
self.__NEXT_HMR_CB = null
}
}
// currentHmrObj will change when ACTION_REFRESH is dispatched.
}, [state.currentHmrObj])

const handleOnUnhandledError = useCallback((error: Error): void => {
// Component stack is added to the error in use-error-handler in case there was a hydration errror
const componentStack = (error as any)._componentStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const ACTION_UNHANDLED_REJECTION = 'unhandled-rejection'
export const ACTION_VERSION_INFO = 'version-info'
export const INITIAL_OVERLAY_STATE: OverlayState = {
nextId: 1,
currentHmrObj: {},
buildError: null,
errors: [],
notFound: false,
Expand Down Expand Up @@ -61,7 +60,6 @@ export type FastRefreshState =
}

export interface OverlayState {
currentHmrObj: {}
nextId: number
buildError: string | null
errors: SupportedErrorEvent[]
Expand Down Expand Up @@ -111,9 +109,6 @@ export const errorOverlayReducer: React.Reducer<
case ACTION_REFRESH: {
return {
...state,
// Create a new hmrObj to track when a HMR was applied, this ensures the HMR callback `useEffect` will be called.
// Uses an object as the identity is unique, so anytime it changes it will trigger a new run of the effect.
currentHmrObj: {},
buildError: null,
errors:
// Errors can come in during updates. In this case, UNHANDLED_ERROR
Expand Down
18 changes: 13 additions & 5 deletions packages/next/src/client/components/use-reducer-with-devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from './router-reducer/router-reducer-types'
import { ActionQueueContext } from '../../shared/lib/router/action-queue'

export type ReduxDevtoolsSyncFn = (state: AppRouterState) => void

function normalizeRouterState(val: any): any {
if (val instanceof Map) {
const obj: { [key: string]: any } = {}
Expand Down Expand Up @@ -86,13 +88,13 @@ export function useUnwrapState(state: ReducerState): AppRouterState {

function useReducerWithReduxDevtoolsNoop(
initialState: AppRouterState
): [ReducerState, Dispatch<ReducerActions>, () => void] {
): [ReducerState, Dispatch<ReducerActions>, ReduxDevtoolsSyncFn] {
return [initialState, () => {}, () => {}]
}

function useReducerWithReduxDevtoolsImpl(
initialState: AppRouterState
): [ReducerState, Dispatch<ReducerActions>, () => void] {
): [ReducerState, Dispatch<ReducerActions>, ReduxDevtoolsSyncFn] {
const [state, setState] = React.useState<ReducerState>(initialState)

const actionQueue = useContext(ActionQueueContext)
Expand Down Expand Up @@ -149,14 +151,20 @@ function useReducerWithReduxDevtoolsImpl(
[actionQueue, initialState]
)

const sync = useCallback(() => {
// Sync is called after a state update in the HistoryUpdater,
// for debugging purposes. Since the reducer state may be a Promise,
// we let the app router use() it and sync on the resolved value if
// something changed.
// Using the `state` here would be referentially unstable and cause
// undesirable re-renders and history updates.
const sync = useCallback<ReduxDevtoolsSyncFn>((resolvedState) => {
if (devtoolsConnectionRef.current) {
devtoolsConnectionRef.current.send(
{ type: 'RENDER_SYNC' },
normalizeRouterState(state)
normalizeRouterState(resolvedState)
)
}
}, [state])
}, [])

return [state, dispatch, sync]
}
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/export/routes/app-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { isDynamicUsageError } from '../helpers/is-dynamic-usage-error'
import {
NEXT_CACHE_TAGS_HEADER,
NEXT_META_SUFFIX,
RSC_PREFETCH_SUFFIX,
RSC_SUFFIX,
} from '../../lib/constants'
Expand Down Expand Up @@ -206,7 +207,7 @@ export async function exportAppPage(

await fileWriter(
ExportedAppPageFiles.META,
htmlFilepath.replace(/\.html$/, '.meta'),
htmlFilepath.replace(/\.html$/, NEXT_META_SUFFIX),
JSON.stringify(meta, null, 2)
)

Expand Down
Loading

0 comments on commit aa629fd

Please sign in to comment.