Add exports for new router (#41368)
Adds `next/navigation` and `next/headers` APIs. Docs will follow later.. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a 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 a 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/examples/adding-examples.md) Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
This commit is contained in:
parent
a315c748c7
commit
562b5a380e
34 changed files with 46 additions and 28 deletions
|
@ -863,6 +863,16 @@ export default async function getBaseWebpackConfig(
|
|||
// let this alias hit before `next` alias.
|
||||
...(isEdgeServer
|
||||
? {
|
||||
// app-router-context can not be ESM and CJS so force CJS
|
||||
'next/dist/shared/lib/app-router-context': path.join(
|
||||
__dirname,
|
||||
'../dist/shared/lib/app-router-context.js'
|
||||
),
|
||||
'next/dist/client/components': path.join(
|
||||
__dirname,
|
||||
'../client/components'
|
||||
),
|
||||
|
||||
'next/dist/client': 'next/dist/esm/client',
|
||||
'next/dist/shared': 'next/dist/esm/shared',
|
||||
'next/dist/pages': 'next/dist/esm/pages',
|
||||
|
@ -1057,7 +1067,7 @@ export default async function getBaseWebpackConfig(
|
|||
}
|
||||
|
||||
const notExternalModules =
|
||||
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|future\/image|constants|dynamic|script)$)|string-hash|private-next-rsc-mod-ref-proxy$)/
|
||||
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|future\/image|constants|dynamic|script|navigation|headers)$)|string-hash|private-next-rsc-mod-ref-proxy$)/
|
||||
if (notExternalModules.test(request)) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
import type { DispatchFn } from './client'
|
||||
import stripAnsi from 'next/dist/compiled/strip-ansi'
|
||||
import formatWebpackMessages from '../../dev/error-overlay/format-webpack-messages'
|
||||
import { useRouter } from '../hooks-client'
|
||||
import { useRouter } from '../navigation'
|
||||
import { errorOverlayReducer } from './internal/error-overlay-reducer'
|
||||
|
||||
function getSocketProtocol(assetPrefix: string): string {
|
||||
|
|
1
packages/next/headers.d.ts
vendored
Normal file
1
packages/next/headers.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './dist/client/components/headers'
|
1
packages/next/headers.js
Normal file
1
packages/next/headers.js
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = require('./dist/client/components/headers')
|
1
packages/next/navigation.d.ts
vendored
Normal file
1
packages/next/navigation.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './dist/client/components/navigation'
|
1
packages/next/navigation.js
Normal file
1
packages/next/navigation.js
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = require('./dist/client/components/navigation')
|
|
@ -48,7 +48,11 @@
|
|||
"types/global.d.ts",
|
||||
"types/compiled.d.ts",
|
||||
"image-types/global.d.ts",
|
||||
"font"
|
||||
"font",
|
||||
"navigation.js",
|
||||
"navigation.d.ts",
|
||||
"headers.js",
|
||||
"headers.d.ts"
|
||||
],
|
||||
"bin": {
|
||||
"next": "./dist/bin/next"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// TODO-APP: support typing for useSelectedLayoutSegment
|
||||
// @ts-ignore
|
||||
import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client'
|
||||
import { useSelectedLayoutSegment } from 'next/navigation'
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
// useSelectedLayoutSegment should not be thrown
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import ClientComp from './client-component'
|
||||
import { headers } from 'next/dist/client/components/hooks-server'
|
||||
import { headers } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
// Opt-in to SSR.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { cookies } from 'next/dist/client/components/hooks-server'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { cookies } from 'next/dist/client/components/hooks-server'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
const cookiesList = cookies()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { headers } from 'next/dist/client/components/hooks-server'
|
||||
import { headers } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { headers } from 'next/dist/client/components/hooks-server'
|
||||
import { headers } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
const headersList = headers()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
// TODO-APP: enable once test is not skipped.
|
||||
// import { useLayoutSegments } from 'next/dist/client/components/hooks-client'
|
||||
// import { useLayoutSegments } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// TODO-APP: enable when implemented.
|
||||
// import { useParams } from 'next/dist/client/components/hooks-client'
|
||||
// import { useParams } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { usePathname } from 'next/dist/client/components/hooks-client'
|
||||
import { usePathname } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
const pathname = usePathname()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// import { usePathname } from 'next/dist/client/components/hooks-client'
|
||||
// import { usePathname } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { previewData } from 'next/dist/client/components/hooks-server'
|
||||
import { previewData } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { previewData } from 'next/dist/client/components/hooks-server'
|
||||
import { previewData } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
const data = previewData()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { useRouter } from 'next/dist/client/components/hooks-client'
|
||||
import { useRouter } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
const router = useRouter()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// import { useRouter } from 'next/dist/client/components/hooks-client'
|
||||
// import { useRouter } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { useSearchParams } from 'next/dist/client/components/hooks-client'
|
||||
import { useSearchParams } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
const params = useSearchParams()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// import { useSearchParams } from 'next/dist/client/components/hooks-client'
|
||||
// import { useSearchParams } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
// TODO-APP: enable once test is not skipped.
|
||||
// import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client'
|
||||
// import { useSelectedLayoutSegment } from 'next/navigation'
|
||||
|
||||
export default function Page() {
|
||||
// This should throw an error.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { useRouter } from 'next/dist/client/components/hooks-client'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import React from 'react'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use client'
|
||||
|
||||
import { TabNavItem } from './TabNavItem'
|
||||
import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client'
|
||||
import { useSelectedLayoutSegment } from 'next/navigation'
|
||||
|
||||
const CategoryNav = ({ categories }) => {
|
||||
const selectedLayoutSegment = useSelectedLayoutSegment()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use client'
|
||||
|
||||
import { TabNavItem } from '../TabNavItem'
|
||||
import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client'
|
||||
import { useSelectedLayoutSegment } from 'next/navigation'
|
||||
|
||||
const SubCategoryNav = ({ category }) => {
|
||||
const selectedLayoutSegment = useSelectedLayoutSegment()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// TODO-APP: enable when flight error serialization is implemented
|
||||
import ClientComp from './client-component'
|
||||
import { headers } from 'next/dist/client/components/hooks-server'
|
||||
import { headers } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
// Opt-in to SSR.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { cookies } from 'next/dist/client/components/hooks-server'
|
||||
import { cookies } from 'next/headers'
|
||||
import Router from './router'
|
||||
|
||||
export default function Page() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import ClientComp from './client-component'
|
||||
import { headers } from 'next/dist/client/components/hooks-server'
|
||||
import { headers } from 'next/headers'
|
||||
|
||||
export default function Page() {
|
||||
// Opt-in to SSR.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Nav from '../components/nav'
|
||||
import { headers } from 'next/dist/client/components/hooks-server'
|
||||
import { headers } from 'next/headers'
|
||||
|
||||
const envVar = process.env.ENV_VAR_TEST
|
||||
const headerKey = 'x-next-test-client'
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import React from 'react'
|
||||
import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
|
||||
import { ServerStyleSheet, StyleSheetManager } from 'styled-components'
|
||||
import { useServerInsertedHTML } from 'next/dist/client/components/hooks-client'
|
||||
import { useServerInsertedHTML } from 'next/navigation'
|
||||
import { useState } from 'react'
|
||||
|
||||
export default function RootStyleRegistry({ children }) {
|
||||
|
|
Loading…
Reference in a new issue