Skip to content

Commit 864602d

Browse files
committed
Remove unstable_rootParams from sources
1 parent 99688f3 commit 864602d

File tree

6 files changed

+5
-199
lines changed

6 files changed

+5
-199
lines changed

crates/next-custom-transforms/src/transforms/react_server_components.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl ReactServerComponentValidator {
645645
],
646646

647647
invalid_client_lib_apis_mapping: FxHashMap::from_iter([
648-
("next/server", vec!["after", "unstable_rootParams"]),
648+
("next/server", vec!["after"]),
649649
(
650650
"next/cache",
651651
vec![

packages/next/server.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ export { URLPattern } from 'next/dist/compiled/@edge-runtime/primitives/url'
1414
export { ImageResponse } from 'next/dist/server/web/spec-extension/image-response'
1515
export type { ImageResponseOptions } from 'next/dist/compiled/@vercel/og/types'
1616
export { after } from 'next/dist/server/after'
17-
export { unstable_rootParams } from 'next/dist/server/request/root-params'
1817
export { connection } from 'next/dist/server/request/connection'

packages/next/server.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ const serverExports = {
1313
.URLPattern,
1414
after: require('next/dist/server/after').after,
1515
connection: require('next/dist/server/request/connection').connection,
16-
unstable_rootParams: require('next/dist/server/request/root-params')
17-
.unstable_rootParams,
1816
}
1917

2018
// https://nodejs.org/api/esm.html#commonjs-namespaces
@@ -30,4 +28,3 @@ exports.userAgent = serverExports.userAgent
3028
exports.URLPattern = serverExports.URLPattern
3129
exports.after = serverExports.after
3230
exports.connection = serverExports.connection
33-
exports.unstable_rootParams = serverExports.unstable_rootParams

packages/next/src/build/webpack/plugins/next-types-plugin/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,7 @@ function isSubpath(parentLayoutPath: string, potentialChildLayoutPath: string) {
402402
)
403403
}
404404

405-
function createServerDefinitions(
406-
rootParams: { param: string; optional: boolean }[]
407-
) {
405+
function createServerDefinitions() {
408406
return `
409407
declare module 'next/server' {
410408
@@ -423,13 +421,6 @@ function createServerDefinitions(
423421
export type { ImageResponseOptions } from 'next/dist/compiled/@vercel/og/types'
424422
export { after } from 'next/dist/server/after'
425423
export { connection } from 'next/dist/server/request/connection'
426-
export function unstable_rootParams(): Promise<{ ${rootParams
427-
.map(
428-
({ param, optional }) =>
429-
// ensure params with dashes are valid keys
430-
`${param.includes('-') ? `'${param}'` : param}${optional ? '?' : ''}: string`
431-
)
432-
.join(', ')} }>
433424
}
434425
`
435426
}
@@ -814,7 +805,7 @@ export class NextTypesPlugin {
814805
compilation.emitAsset(
815806
serverTypesPath,
816807
new sources.RawSource(
817-
createServerDefinitions(rootParams)
808+
createServerDefinitions()
818809
) as unknown as webpack.sources.RawSource
819810
)
820811
}

packages/next/src/server/request/root-params.ts

Lines changed: 2 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -14,189 +14,9 @@ import {
1414
type StaticPrerenderStore,
1515
} from '../app-render/work-unit-async-storage.external'
1616
import { makeHangingPromise } from '../dynamic-rendering-utils'
17-
import type { OpaqueFallbackRouteParams } from './fallback-params'
18-
import type { Params, ParamValue } from './params'
19-
import {
20-
describeStringPropertyAccess,
21-
wellKnownProperties,
22-
} from '../../shared/lib/utils/reflect-utils'
17+
import type { ParamValue } from './params'
18+
import { describeStringPropertyAccess } from '../../shared/lib/utils/reflect-utils'
2319
import { actionAsyncStorage } from '../app-render/action-async-storage.external'
24-
import { warnOnce } from '../../build/output/log'
25-
26-
interface CacheLifetime {}
27-
const CachedParams = new WeakMap<CacheLifetime, Promise<Params>>()
28-
29-
/**
30-
* @deprecated import specific root params from `next/root-params` instead.
31-
*/
32-
export async function unstable_rootParams(): Promise<Params> {
33-
warnOnce(
34-
'`unstable_rootParams()` is deprecated and will be removed in an upcoming major release. Import specific root params from `next/root-params` instead.'
35-
)
36-
const workStore = workAsyncStorage.getStore()
37-
if (!workStore) {
38-
throw new InvariantError('Missing workStore in unstable_rootParams')
39-
}
40-
41-
const workUnitStore = workUnitAsyncStorage.getStore()
42-
43-
if (!workUnitStore) {
44-
throw new Error(
45-
`Route ${workStore.route} used \`unstable_rootParams()\` in Pages Router. This API is only available within App Router.`
46-
)
47-
}
48-
49-
switch (workUnitStore.type) {
50-
case 'cache':
51-
case 'unstable-cache': {
52-
throw new Error(
53-
`Route ${workStore.route} used \`unstable_rootParams()\` inside \`"use cache"\` or \`unstable_cache\`. Support for this API inside cache scopes is planned for a future version of Next.js.`
54-
)
55-
}
56-
case 'prerender':
57-
case 'prerender-client':
58-
case 'prerender-ppr':
59-
case 'prerender-legacy':
60-
return createPrerenderRootParams(
61-
workUnitStore.rootParams,
62-
workStore,
63-
workUnitStore
64-
)
65-
case 'private-cache':
66-
case 'prerender-runtime':
67-
case 'request':
68-
return Promise.resolve(workUnitStore.rootParams)
69-
default:
70-
return workUnitStore satisfies never
71-
}
72-
}
73-
74-
function createPrerenderRootParams(
75-
underlyingParams: Params,
76-
workStore: WorkStore,
77-
prerenderStore: StaticPrerenderStore
78-
): Promise<Params> {
79-
switch (prerenderStore.type) {
80-
case 'prerender-client': {
81-
const exportName = '`unstable_rootParams`'
82-
throw new InvariantError(
83-
`${exportName} must not be used within a client component. Next.js should be preventing ${exportName} from being included in client components statically, but did not in this case.`
84-
)
85-
}
86-
case 'prerender': {
87-
const fallbackParams = prerenderStore.fallbackRouteParams
88-
if (fallbackParams) {
89-
for (const key in underlyingParams) {
90-
if (fallbackParams.has(key)) {
91-
const cachedParams = CachedParams.get(underlyingParams)
92-
if (cachedParams) {
93-
return cachedParams
94-
}
95-
96-
const promise = makeHangingPromise<Params>(
97-
prerenderStore.renderSignal,
98-
workStore.route,
99-
'`unstable_rootParams`'
100-
)
101-
CachedParams.set(underlyingParams, promise)
102-
103-
return promise
104-
}
105-
}
106-
}
107-
break
108-
}
109-
case 'prerender-ppr': {
110-
const fallbackParams = prerenderStore.fallbackRouteParams
111-
if (fallbackParams) {
112-
for (const key in underlyingParams) {
113-
if (fallbackParams.has(key)) {
114-
// We have fallback params at this level so we need to make an erroring
115-
// params object which will postpone if you access the fallback params
116-
return makeErroringRootParams(
117-
underlyingParams,
118-
fallbackParams,
119-
workStore,
120-
prerenderStore
121-
)
122-
}
123-
}
124-
}
125-
break
126-
}
127-
case 'prerender-legacy':
128-
break
129-
default:
130-
prerenderStore satisfies never
131-
}
132-
133-
// We don't have any fallback params so we have an entirely static safe params object
134-
return Promise.resolve(underlyingParams)
135-
}
136-
137-
function makeErroringRootParams(
138-
underlyingParams: Params,
139-
fallbackParams: OpaqueFallbackRouteParams,
140-
workStore: WorkStore,
141-
prerenderStore: PrerenderStorePPR | PrerenderStoreLegacy
142-
): Promise<Params> {
143-
const cachedParams = CachedParams.get(underlyingParams)
144-
if (cachedParams) {
145-
return cachedParams
146-
}
147-
148-
const augmentedUnderlying = { ...underlyingParams }
149-
150-
// We don't use makeResolvedReactPromise here because params
151-
// supports copying with spread and we don't want to unnecessarily
152-
// instrument the promise with spreadable properties of ReactPromise.
153-
const promise = Promise.resolve(augmentedUnderlying)
154-
CachedParams.set(underlyingParams, promise)
155-
156-
Object.keys(underlyingParams).forEach((prop) => {
157-
if (wellKnownProperties.has(prop)) {
158-
// These properties cannot be shadowed because they need to be the
159-
// true underlying value for Promises to work correctly at runtime
160-
} else {
161-
if (fallbackParams.has(prop)) {
162-
Object.defineProperty(augmentedUnderlying, prop, {
163-
get() {
164-
const expression = describeStringPropertyAccess(
165-
'unstable_rootParams',
166-
prop
167-
)
168-
// In most dynamic APIs we also throw if `dynamic = "error"` however
169-
// for params is only dynamic when we're generating a fallback shell
170-
// and even when `dynamic = "error"` we still support generating dynamic
171-
// fallback shells
172-
// TODO remove this comment when cacheComponents is the default since there
173-
// will be no `dynamic = "error"`
174-
if (prerenderStore.type === 'prerender-ppr') {
175-
// PPR Prerender (no cacheComponents)
176-
postponeWithTracking(
177-
workStore.route,
178-
expression,
179-
prerenderStore.dynamicTracking
180-
)
181-
} else {
182-
// Legacy Prerender
183-
throwToInterruptStaticGeneration(
184-
expression,
185-
workStore,
186-
prerenderStore
187-
)
188-
}
189-
},
190-
enumerable: true,
191-
})
192-
} else {
193-
;(promise as any)[prop] = underlyingParams[prop]
194-
}
195-
}
196-
})
197-
198-
return promise
199-
}
20020

20121
/**
20222
* Used for the compiler-generated `next/root-params` module.

packages/next/src/server/web/exports/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ export { userAgent, userAgentFromString } from '../spec-extension/user-agent'
77
export { URLPattern } from '../spec-extension/url-pattern'
88
export { after } from '../../after'
99
export { connection } from '../../request/connection'
10-
export { unstable_rootParams } from '../../request/root-params'

0 commit comments

Comments
 (0)