Unverified Commit e2286eeb authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add additional comments to new router (#38986)

Expanded app-render.


## 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 8c902b61
......@@ -41,6 +41,7 @@ function fetchFlight(
JSON.stringify(flightRouterState)
)
// TODO-APP: Verify that TransformStream is supported.
const { readable, writable } = new TransformStream()
fetch(flightUrl.toString()).then((res) => {
......
......@@ -12,16 +12,25 @@ import {
AppTreeContext,
} from '../../shared/lib/app-router-context'
/**
* Get the current search params. For example useSearchParams() would return {"foo": "bar"} when ?foo=bar
*/
export function useSearchParams() {
return useContext(SearchParamsContext)
}
/**
* Get an individual search param. For example useSearchParam("foo") would return "bar" when ?foo=bar
*/
export function useSearchParam(key: string): string | string[] {
const params = useContext(SearchParamsContext)
return params[key]
}
// TODO-APP: Move the other router context over to this one
/**
* Get the router methods. For example router.push('/dashboard')
*/
export function useRouter(): import('../../shared/lib/app-router-context').AppRouterInstance {
return useContext(AppRouterContext)
}
......@@ -31,6 +40,9 @@ export function useRouter(): import('../../shared/lib/app-router-context').AppRo
// return useContext(ParamsContext)
// }
/**
* Get the current pathname. For example usePathname() on /dashboard?foo=bar would return "/dashboard"
*/
export function usePathname(): string {
return useContext(PathnameContext)
}
......@@ -40,6 +52,10 @@ export function usePathname(): string {
// return useContext(LayoutSegmentsContext)
// }
// TODO-APP: Expand description when the docs are written for it.
/**
* Get the current segment one level down from the layout.
*/
export function useSelectedLayoutSegment(
parallelRouteKey: string = 'children'
): string {
......
This diff is collapsed.
......@@ -53,7 +53,7 @@ import { getExtension, serveStatic } from './serve-static'
import { ParsedUrlQuery } from 'querystring'
import { apiResolver } from './api-utils/node'
import { RenderOpts, renderToHTML } from './render'
import { renderToHTML as appRenderToHTML } from './app-render'
import { renderToHTMLOrFlight as appRenderToHTMLOrFlight } from './app-render'
import { ParsedUrl, parseUrl } from '../shared/lib/router/utils/parse-url'
import * as Log from '../build/output/log'
......@@ -615,7 +615,7 @@ export default class NextNodeServer extends BaseServer {
(renderOpts.isAppPath || query.__flight__)
) {
const isPagesDir = !renderOpts.isAppPath
return appRenderToHTML(
return appRenderToHTMLOrFlight(
req.originalRequest,
res.originalResponse,
pathname,
......
......@@ -3,14 +3,13 @@ import type { FocusRef } from '../../client/components/reducer'
import type { FlightRouterState, FlightData } from '../../server/app-render'
export type ChildSegmentMap = Map<string, CacheNode>
type ParallelRoutesCacheNodes = Map<string, ChildSegmentMap>
export type CacheNode = {
data: ReturnType<
typeof import('../../client/components/app-router.client').fetchServerResponse
> | null
subTreeData: null | React.ReactNode
parallelRoutes: ParallelRoutesCacheNodes
parallelRoutes: Map<string, ChildSegmentMap>
}
export type AppRouterInstance = {
......
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