Skip to content

Commit

Permalink
Move App Router client-side constants to separate file (#59239)
Browse files Browse the repository at this point in the history
## What?

Noticed constants.js was included in the client-side bundle. This
ensures only the needed constants are included.


## How?

Created a separate file for client-side constants.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-1789
  • Loading branch information
timneutkens authored Dec 6, 2023
1 parent 50d4578 commit 4f67cbf
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
MIDDLEWARE_FILENAME,
PAGES_DIR_ALIAS,
INSTRUMENTATION_HOOK_FILENAME,
NEXT_DID_POSTPONE_HEADER,
RSC_PREFETCH_SUFFIX,
RSC_SUFFIX,
} from '../lib/constants'
Expand Down Expand Up @@ -142,6 +141,7 @@ import {
RSC_HEADER,
RSC_CONTENT_TYPE_HEADER,
RSC_VARY_HEADER,
NEXT_DID_POSTPONE_HEADER,
} from '../client/components/app-router-headers'
import { webpackBuild } from './webpack-build'
import { NextBuildContext } from './build-context'
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/client/components/app-router-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export const FLIGHT_PARAMETERS = [
] as const

export const NEXT_RSC_UNION_QUERY = '_rsc' as const

export const NEXT_DID_POSTPONE_HEADER = 'x-nextjs-postponed' as const
5 changes: 5 additions & 0 deletions packages/next/src/client/components/redirect-status-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum RedirectStatusCode {
SeeOther = 303,
TemporaryRedirect = 307,
PermanentRedirect = 308,
}
2 changes: 1 addition & 1 deletion packages/next/src/client/components/redirect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { requestAsyncStorage } from './request-async-storage.external'
import type { ResponseCookies } from '../../server/web/spec-extension/cookies'
import { actionAsyncStorage } from './action-async-storage.external'
import { RedirectStatusCode } from '../../shared/lib/constants'
import { RedirectStatusCode } from './redirect-status-code'

const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
NEXT_URL,
RSC_HEADER,
RSC_CONTENT_TYPE_HEADER,
NEXT_DID_POSTPONE_HEADER,
} from '../app-router-headers'
import { urlToUrlWithoutFlightMarker } from '../app-router'
import { callServer } from '../../app-call-server'
import { PrefetchKind } from './router-reducer-types'
import { hexHash } from '../../../shared/lib/hash'
import { NEXT_DID_POSTPONE_HEADER } from '../../../lib/constants'

export type FetchServerResponseResult = [
flightData: FlightData,
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export const PRERENDER_REVALIDATE_HEADER = 'x-prerender-revalidate'
export const PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER =
'x-prerender-revalidate-if-generated'

export const NEXT_DID_POSTPONE_HEADER = 'x-nextjs-postponed'

export const RSC_PREFETCH_SUFFIX = '.prefetch.rsc'
export const RSC_SUFFIX = '.rsc'
export const NEXT_DATA_SUFFIX = '.json'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/lib/redirect-status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RedirectStatusCode } from '../shared/lib/constants'
import { RedirectStatusCode } from '../client/components/redirect-status-code'

export const allowedStatusCodes = new Set([301, 302, 303, 307, 308])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../client/components/redirect'
import { renderToReadableStream } from 'react-dom/server.edge'
import { streamToString } from '../stream-utils/node-web-streams-helper'
import { RedirectStatusCode } from '../../shared/lib/constants'
import { RedirectStatusCode } from '../../client/components/redirect-status-code'

export function makeGetServerInsertedHTML({
polyfills,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/base-http/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'
import type { I18NConfig } from '../config-shared'

import { RedirectStatusCode } from '../../shared/lib/constants'
import { RedirectStatusCode } from '../../client/components/redirect-status-code'
import type { NextApiRequestCookies } from '../api-utils'
import { getCookieParser } from '../api-utils/get-cookie-parser'

Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ import {
APP_PATHS_MANIFEST,
NEXT_BUILTIN_DOCUMENT,
PAGES_MANIFEST,
RedirectStatusCode,
STATIC_STATUS_PAGES,
} from '../shared/lib/constants'
import { RedirectStatusCode } from '../client/components/redirect-status-code'
import { isDynamicRoute } from '../shared/lib/router/utils'
import { checkIsOnDemandRevalidate } from './api-utils'
import { setConfig } from '../shared/lib/runtime-config.external'
Expand Down Expand Up @@ -83,6 +83,7 @@ import {
RSC_VARY_HEADER,
NEXT_RSC_UNION_QUERY,
NEXT_ROUTER_PREFETCH_HEADER,
NEXT_DID_POSTPONE_HEADER,
} from '../client/components/app-router-headers'
import type {
MatchOptions,
Expand All @@ -107,7 +108,6 @@ import {
import {
CACHE_ONE_YEAR,
NEXT_CACHE_TAGS_HEADER,
NEXT_DID_POSTPONE_HEADER,
NEXT_QUERY_PARAM_PREFIX,
} from '../lib/constants'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/router-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import { isPostpone } from './router-utils/is-postpone'
import {
PHASE_PRODUCTION_SERVER,
PHASE_DEVELOPMENT_SERVER,
RedirectStatusCode,
} from '../../shared/lib/constants'
import { RedirectStatusCode } from '../../client/components/redirect-status-code'
import { DevBundlerService } from './dev-bundler-service'
import { type Span, trace } from '../../trace'

Expand Down
6 changes: 0 additions & 6 deletions packages/next/src/shared/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,3 @@ export const SYSTEM_ENTRYPOINTS = new Set<string>([
CLIENT_STATIC_FILES_RUNTIME_AMP,
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP,
])

export enum RedirectStatusCode {
SeeOther = 303,
TemporaryRedirect = 307,
PermanentRedirect = 308,
}

0 comments on commit 4f67cbf

Please sign in to comment.