Unverified Commit 8fc8a6c8 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add comments in new router reducer (#39025)

Expand explanation of new router.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 90ddd0dc
......@@ -2,7 +2,7 @@ import React, { useEffect } from 'react'
import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack'
import {
AppRouterContext,
AppTreeContext,
LayoutRouterContext,
GlobalLayoutRouterContext,
} from '../../shared/lib/app-router-context'
import type {
......@@ -99,7 +99,7 @@ export default function AppRouter({
children: React.ReactNode
hotReloader?: React.ReactNode
}) {
const [{ tree, cache, pushRef, focusRef, canonicalUrl }, dispatch] =
const [{ tree, cache, pushRef, focusAndScrollRef, canonicalUrl }, dispatch] =
React.useReducer(reducer, {
tree: initialTree,
cache: {
......@@ -109,7 +109,7 @@ export default function AppRouter({
typeof window === 'undefined' ? new Map() : initialParallelRoutes,
},
pushRef: { pendingPush: false, mpaNavigation: false },
focusRef: { focus: false },
focusAndScrollRef: { apply: false },
canonicalUrl:
initialCanonicalUrl +
// Hash is read as the initial value for canonicalUrl in the browser
......@@ -300,11 +300,11 @@ export default function AppRouter({
value={{
changeByServerResponse,
tree,
focusRef,
focusAndScrollRef,
}}
>
<AppRouterContext.Provider value={appRouter}>
<AppTreeContext.Provider
<LayoutRouterContext.Provider
value={{
childNodes: cache.parallelRoutes,
tree: tree,
......@@ -324,7 +324,7 @@ export default function AppRouter({
// HotReloader uses the router tree and router.reload() in order to apply Server Component changes.
hotReloader
}
</AppTreeContext.Provider>
</LayoutRouterContext.Provider>
</AppRouterContext.Provider>
</GlobalLayoutRouterContext.Provider>
</SearchParamsContext.Provider>
......
......@@ -9,7 +9,7 @@ import {
} from './hooks-client-context'
import {
AppRouterContext,
AppTreeContext,
LayoutRouterContext,
} from '../../shared/lib/app-router-context'
/**
......@@ -59,7 +59,7 @@ export function usePathname(): string {
export function useSelectedLayoutSegment(
parallelRouteKey: string = 'children'
): string {
const { tree } = useContext(AppTreeContext)
const { tree } = useContext(LayoutRouterContext)
const segment = tree[1][parallelRouteKey][0]
......
This diff is collapsed.
import React from 'react'
import type { FocusRef } from '../../client/components/reducer'
import type { FocusAndScrollRef } from '../../client/components/reducer'
import type { FlightRouterState, FlightData } from '../../server/app-render'
export type ChildSegmentMap = Map<string, CacheNode>
......@@ -46,7 +46,7 @@ export type AppRouterInstance = {
export const AppRouterContext = React.createContext<AppRouterInstance>(
null as any
)
export const AppTreeContext = React.createContext<{
export const LayoutRouterContext = React.createContext<{
childNodes: CacheNode['parallelRoutes']
tree: FlightRouterState
url: string
......@@ -58,11 +58,11 @@ export const GlobalLayoutRouterContext = React.createContext<{
previousTree: FlightRouterState,
flightData: FlightData
) => void
focusRef: FocusRef
focusAndScrollRef: FocusAndScrollRef
}>(null as any)
if (process.env.NODE_ENV !== 'production') {
AppRouterContext.displayName = 'AppRouterContext'
AppTreeContext.displayName = 'AppTreeContext'
LayoutRouterContext.displayName = 'LayoutRouterContext'
GlobalLayoutRouterContext.displayName = 'GlobalLayoutRouterContext'
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment