Skip to content

Commit

Permalink
Add exports for new router (vercel#41368)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and Kikobeats committed Oct 24, 2022
1 parent 721ad89 commit 0bf74e8
Show file tree
Hide file tree
Showing 34 changed files with 46 additions and 28 deletions.
12 changes: 11 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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
}
Expand Down
File renamed without changes.
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/next/headers.d.ts
@@ -0,0 +1 @@
export * from './dist/client/components/headers'
1 change: 1 addition & 0 deletions packages/next/headers.js
@@ -0,0 +1 @@
module.exports = require('./dist/client/components/headers')
1 change: 1 addition & 0 deletions packages/next/navigation.d.ts
@@ -0,0 +1 @@
export * from './dist/client/components/navigation'
1 change: 1 addition & 0 deletions packages/next/navigation.js
@@ -0,0 +1 @@
module.exports = require('./dist/client/components/navigation')
6 changes: 5 additions & 1 deletion packages/next/package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-edge/app/app-edge/layout.tsx
Expand Up @@ -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
Expand Down
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-cookies/client/page.js
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-cookies/page.js
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-headers/client/page.js
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-headers/page.js
@@ -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()
Expand Down
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-params/server/page.js
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-pathname/page.js
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-pathname/server/page.js
@@ -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.
Expand Down
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-preview-data/page.js
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-router/page.js
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-router/server/page.js
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/hooks/use-search-params/page.js
@@ -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()
Expand Down
@@ -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.
Expand Down
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/navigation/link.js
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/nested-navigation/CategoryNav.js
@@ -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()
Expand Down
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/not-found/clientcomponent/a.js
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/old-router/page.js
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app/app/redirect/clientcomponent/page.js
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/rsc-basic/app/page.js
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/rsc-basic/app/root-style-registry.js
Expand Up @@ -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 }) {
Expand Down

0 comments on commit 0bf74e8

Please sign in to comment.