Unverified Commit 4f67cbfe authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Move App Router client-side constants to separate file (#59239)

## 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
parent 50d45787
......@@ -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'
......@@ -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'
......
......@@ -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
export enum RedirectStatusCode {
SeeOther = 303,
TemporaryRedirect = 307,
PermanentRedirect = 308,
}
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'
......
......@@ -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,
......
......@@ -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'
......
import { RedirectStatusCode } from '../shared/lib/constants'
import { RedirectStatusCode } from '../client/components/redirect-status-code'
export const allowedStatusCodes = new Set([301, 302, 303, 307, 308])
......
......@@ -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,
......
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'
......
......@@ -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'
......@@ -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,
......@@ -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'
......
......@@ -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'
......
......@@ -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,
}
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