inital commit

This commit is contained in:
2026-01-01 15:25:19 +05:30
commit f0ae49465a
36361 changed files with 4894111 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
import { workAsyncStorage } from '../app-render/work-async-storage.external';
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external';
import { postponeWithTracking, throwToInterruptStaticGeneration, trackDynamicDataInDynamicRender } from '../app-render/dynamic-rendering';
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout';
import { makeHangingPromise } from '../dynamic-rendering-utils';
import { isRequestAPICallableInsideAfter } from './utils';
/**
* This function allows you to indicate that you require an actual user Request before continuing.
*
* During prerendering it will never resolve and during rendering it resolves immediately.
*/ export function connection() {
const workStore = workAsyncStorage.getStore();
const workUnitStore = workUnitAsyncStorage.getStore();
if (workStore) {
if (workUnitStore && workUnitStore.phase === 'after' && !isRequestAPICallableInsideAfter()) {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "connection" inside "after(...)". The \`connection()\` function is used to indicate the subsequent code must only run when there is an actual Request, but "after(...)" executes after the request, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/after`), "__NEXT_ERROR_CODE", {
value: "E186",
enumerable: false,
configurable: true
});
}
if (workStore.forceStatic) {
// When using forceStatic we override all other logic and always just return an empty
// headers object without tracking
return Promise.resolve(undefined);
}
if (workUnitStore) {
if (workUnitStore.type === 'cache') {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "connection" inside "use cache". The \`connection()\` function is used to indicate the subsequent code must only run when there is an actual Request, but caches must be able to be produced before a Request so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`), "__NEXT_ERROR_CODE", {
value: "E111",
enumerable: false,
configurable: true
});
} else if (workUnitStore.type === 'unstable-cache') {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "connection" inside a function cached with "unstable_cache(...)". The \`connection()\` function is used to indicate the subsequent code must only run when there is an actual Request, but caches must be able to be produced before a Request so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache`), "__NEXT_ERROR_CODE", {
value: "E1",
enumerable: false,
configurable: true
});
}
}
if (workStore.dynamicShouldError) {
throw Object.defineProperty(new StaticGenBailoutError(`Route ${workStore.route} with \`dynamic = "error"\` couldn't be rendered statically because it used \`connection\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`), "__NEXT_ERROR_CODE", {
value: "E562",
enumerable: false,
configurable: true
});
}
if (workUnitStore) {
if (workUnitStore.type === 'prerender') {
// dynamicIO Prerender
// We return a promise that never resolves to allow the prender to stall at this point
return makeHangingPromise(workUnitStore.renderSignal, '`connection()`');
} else if (workUnitStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
// We use React's postpone API to interrupt rendering here to create a dynamic hole
postponeWithTracking(workStore.route, 'connection', workUnitStore.dynamicTracking);
} else if (workUnitStore.type === 'prerender-legacy') {
// Legacy Prerender
// We throw an error here to interrupt prerendering to mark the route as dynamic
throwToInterruptStaticGeneration('connection', workStore, workUnitStore);
}
}
// We fall through to the dynamic context below but we still track dynamic access
// because in dev we can still error for things like using headers inside a cache context
trackDynamicDataInDynamicRender(workStore, workUnitStore);
}
return Promise.resolve(undefined);
}
//# sourceMappingURL=connection.js.map

File diff suppressed because one or more lines are too long

409
node_modules/next/dist/esm/server/request/cookies.js generated vendored Normal file
View File

@@ -0,0 +1,409 @@
import { areCookiesMutableInCurrentPhase, RequestCookiesAdapter } from '../web/spec-extension/adapters/request-cookies';
import { RequestCookies } from '../web/spec-extension/cookies';
import { workAsyncStorage } from '../app-render/work-async-storage.external';
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external';
import { postponeWithTracking, abortAndThrowOnSynchronousRequestDataAccess, throwToInterruptStaticGeneration, trackDynamicDataInDynamicRender, trackSynchronousRequestDataAccessInDev } from '../app-render/dynamic-rendering';
import { getExpectedRequestStore } from '../app-render/work-unit-async-storage.external';
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout';
import { makeHangingPromise } from '../dynamic-rendering-utils';
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger';
import { scheduleImmediate } from '../../lib/scheduler';
import { isRequestAPICallableInsideAfter } from './utils';
export function cookies() {
const callingExpression = 'cookies';
const workStore = workAsyncStorage.getStore();
const workUnitStore = workUnitAsyncStorage.getStore();
if (workStore) {
if (workUnitStore && workUnitStore.phase === 'after' && !isRequestAPICallableInsideAfter()) {
throw Object.defineProperty(new Error(// TODO(after): clarify that this only applies to pages?
`Route ${workStore.route} used "cookies" inside "after(...)". This is not supported. If you need this data inside an "after" callback, use "cookies" outside of the callback. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/after`), "__NEXT_ERROR_CODE", {
value: "E88",
enumerable: false,
configurable: true
});
}
if (workStore.forceStatic) {
// When using forceStatic we override all other logic and always just return an empty
// cookies object without tracking
const underlyingCookies = createEmptyCookies();
return makeUntrackedExoticCookies(underlyingCookies);
}
if (workUnitStore) {
if (workUnitStore.type === 'cache') {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "cookies" inside "use cache". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use "cookies" outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`), "__NEXT_ERROR_CODE", {
value: "E398",
enumerable: false,
configurable: true
});
} else if (workUnitStore.type === 'unstable-cache') {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "cookies" inside a function cached with "unstable_cache(...)". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use "cookies" outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache`), "__NEXT_ERROR_CODE", {
value: "E157",
enumerable: false,
configurable: true
});
}
}
if (workStore.dynamicShouldError) {
throw Object.defineProperty(new StaticGenBailoutError(`Route ${workStore.route} with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`), "__NEXT_ERROR_CODE", {
value: "E549",
enumerable: false,
configurable: true
});
}
if (workUnitStore) {
if (workUnitStore.type === 'prerender') {
// dynamicIO Prerender
// We don't track dynamic access here because access will be tracked when you access
// one of the properties of the cookies object.
return makeDynamicallyTrackedExoticCookies(workStore.route, workUnitStore);
} else if (workUnitStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
// We are prerendering with PPR. We need track dynamic access here eagerly
// to keep continuity with how cookies has worked in PPR without dynamicIO.
postponeWithTracking(workStore.route, callingExpression, workUnitStore.dynamicTracking);
} else if (workUnitStore.type === 'prerender-legacy') {
// Legacy Prerender
// We track dynamic access here so we don't need to wrap the cookies in
// individual property access tracking.
throwToInterruptStaticGeneration(callingExpression, workStore, workUnitStore);
}
}
// We fall through to the dynamic context below but we still track dynamic access
// because in dev we can still error for things like using cookies inside a cache context
trackDynamicDataInDynamicRender(workStore, workUnitStore);
}
// cookies is being called in a dynamic context
const requestStore = getExpectedRequestStore(callingExpression);
let underlyingCookies;
if (areCookiesMutableInCurrentPhase(requestStore)) {
// We can't conditionally return different types here based on the context.
// To avoid confusion, we always return the readonly type here.
underlyingCookies = requestStore.userspaceMutableCookies;
} else {
underlyingCookies = requestStore.cookies;
}
if (process.env.NODE_ENV === 'development' && !(workStore == null ? void 0 : workStore.isPrefetchRequest)) {
return makeUntrackedExoticCookiesWithDevWarnings(underlyingCookies, workStore == null ? void 0 : workStore.route);
} else {
return makeUntrackedExoticCookies(underlyingCookies);
}
}
function createEmptyCookies() {
return RequestCookiesAdapter.seal(new RequestCookies(new Headers({})));
}
const CachedCookies = new WeakMap();
function makeDynamicallyTrackedExoticCookies(route, prerenderStore) {
const cachedPromise = CachedCookies.get(prerenderStore);
if (cachedPromise) {
return cachedPromise;
}
const promise = makeHangingPromise(prerenderStore.renderSignal, '`cookies()`');
CachedCookies.set(prerenderStore, promise);
Object.defineProperties(promise, {
[Symbol.iterator]: {
value: function() {
const expression = '`cookies()[Symbol.iterator]()`';
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
size: {
get () {
const expression = '`cookies().size`';
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
get: {
value: function get() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().get()`';
} else {
expression = `\`cookies().get(${describeNameArg(arguments[0])})\``;
}
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
getAll: {
value: function getAll() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().getAll()`';
} else {
expression = `\`cookies().getAll(${describeNameArg(arguments[0])})\``;
}
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
has: {
value: function has() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().has()`';
} else {
expression = `\`cookies().has(${describeNameArg(arguments[0])})\``;
}
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
set: {
value: function set() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().set()`';
} else {
const arg = arguments[0];
if (arg) {
expression = `\`cookies().set(${describeNameArg(arg)}, ...)\``;
} else {
expression = '`cookies().set(...)`';
}
}
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
delete: {
value: function() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().delete()`';
} else if (arguments.length === 1) {
expression = `\`cookies().delete(${describeNameArg(arguments[0])})\``;
} else {
expression = `\`cookies().delete(${describeNameArg(arguments[0])}, ...)\``;
}
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
clear: {
value: function clear() {
const expression = '`cookies().clear()`';
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
toString: {
value: function toString() {
const expression = '`cookies().toString()`';
const error = createCookiesAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
}
});
return promise;
}
function makeUntrackedExoticCookies(underlyingCookies) {
const cachedCookies = CachedCookies.get(underlyingCookies);
if (cachedCookies) {
return cachedCookies;
}
const promise = Promise.resolve(underlyingCookies);
CachedCookies.set(underlyingCookies, promise);
Object.defineProperties(promise, {
[Symbol.iterator]: {
value: underlyingCookies[Symbol.iterator] ? underlyingCookies[Symbol.iterator].bind(underlyingCookies) : // We should remove this and unify our cookies types. We could just let this continue to throw lazily
// but that's already a hard thing to debug so we may as well implement it consistently. The biggest problem with
// implementing this in this way is the underlying cookie type is a ResponseCookie and not a RequestCookie and so it
// has extra properties not available on RequestCookie instances.
polyfilledResponseCookiesIterator.bind(underlyingCookies)
},
size: {
get () {
return underlyingCookies.size;
}
},
get: {
value: underlyingCookies.get.bind(underlyingCookies)
},
getAll: {
value: underlyingCookies.getAll.bind(underlyingCookies)
},
has: {
value: underlyingCookies.has.bind(underlyingCookies)
},
set: {
value: underlyingCookies.set.bind(underlyingCookies)
},
delete: {
value: underlyingCookies.delete.bind(underlyingCookies)
},
clear: {
value: // @ts-expect-error clear is defined in RequestCookies implementation but not in the type
typeof underlyingCookies.clear === 'function' ? underlyingCookies.clear.bind(underlyingCookies) : // We should remove this and unify our cookies types. We could just let this continue to throw lazily
// but that's already a hard thing to debug so we may as well implement it consistently. The biggest problem with
// implementing this in this way is the underlying cookie type is a ResponseCookie and not a RequestCookie and so it
// has extra properties not available on RequestCookie instances.
polyfilledResponseCookiesClear.bind(underlyingCookies, promise)
},
toString: {
value: underlyingCookies.toString.bind(underlyingCookies)
}
});
return promise;
}
function makeUntrackedExoticCookiesWithDevWarnings(underlyingCookies, route) {
const cachedCookies = CachedCookies.get(underlyingCookies);
if (cachedCookies) {
return cachedCookies;
}
const promise = new Promise((resolve)=>scheduleImmediate(()=>resolve(underlyingCookies)));
CachedCookies.set(underlyingCookies, promise);
Object.defineProperties(promise, {
[Symbol.iterator]: {
value: function() {
const expression = '`...cookies()` or similar iteration';
syncIODev(route, expression);
return underlyingCookies[Symbol.iterator] ? underlyingCookies[Symbol.iterator].apply(underlyingCookies, arguments) : // We should remove this and unify our cookies types. We could just let this continue to throw lazily
// but that's already a hard thing to debug so we may as well implement it consistently. The biggest problem with
// implementing this in this way is the underlying cookie type is a ResponseCookie and not a RequestCookie and so it
// has extra properties not available on RequestCookie instances.
polyfilledResponseCookiesIterator.call(underlyingCookies);
},
writable: false
},
size: {
get () {
const expression = '`cookies().size`';
syncIODev(route, expression);
return underlyingCookies.size;
}
},
get: {
value: function get() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().get()`';
} else {
expression = `\`cookies().get(${describeNameArg(arguments[0])})\``;
}
syncIODev(route, expression);
return underlyingCookies.get.apply(underlyingCookies, arguments);
},
writable: false
},
getAll: {
value: function getAll() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().getAll()`';
} else {
expression = `\`cookies().getAll(${describeNameArg(arguments[0])})\``;
}
syncIODev(route, expression);
return underlyingCookies.getAll.apply(underlyingCookies, arguments);
},
writable: false
},
has: {
value: function get() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().has()`';
} else {
expression = `\`cookies().has(${describeNameArg(arguments[0])})\``;
}
syncIODev(route, expression);
return underlyingCookies.has.apply(underlyingCookies, arguments);
},
writable: false
},
set: {
value: function set() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().set()`';
} else {
const arg = arguments[0];
if (arg) {
expression = `\`cookies().set(${describeNameArg(arg)}, ...)\``;
} else {
expression = '`cookies().set(...)`';
}
}
syncIODev(route, expression);
return underlyingCookies.set.apply(underlyingCookies, arguments);
},
writable: false
},
delete: {
value: function() {
let expression;
if (arguments.length === 0) {
expression = '`cookies().delete()`';
} else if (arguments.length === 1) {
expression = `\`cookies().delete(${describeNameArg(arguments[0])})\``;
} else {
expression = `\`cookies().delete(${describeNameArg(arguments[0])}, ...)\``;
}
syncIODev(route, expression);
return underlyingCookies.delete.apply(underlyingCookies, arguments);
},
writable: false
},
clear: {
value: function clear() {
const expression = '`cookies().clear()`';
syncIODev(route, expression);
// @ts-ignore clear is defined in RequestCookies implementation but not in the type
return typeof underlyingCookies.clear === 'function' ? underlyingCookies.clear.apply(underlyingCookies, arguments) : // We should remove this and unify our cookies types. We could just let this continue to throw lazily
// but that's already a hard thing to debug so we may as well implement it consistently. The biggest problem with
// implementing this in this way is the underlying cookie type is a ResponseCookie and not a RequestCookie and so it
// has extra properties not available on RequestCookie instances.
polyfilledResponseCookiesClear.call(underlyingCookies, promise);
},
writable: false
},
toString: {
value: function toString() {
const expression = '`cookies().toString()` or implicit casting';
syncIODev(route, expression);
return underlyingCookies.toString.apply(underlyingCookies, arguments);
},
writable: false
}
});
return promise;
}
function describeNameArg(arg) {
return typeof arg === 'object' && arg !== null && typeof arg.name === 'string' ? `'${arg.name}'` : typeof arg === 'string' ? `'${arg}'` : '...';
}
function syncIODev(route, expression) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore && workUnitStore.type === 'request' && workUnitStore.prerenderPhase === true) {
// When we're rendering dynamically in dev we need to advance out of the
// Prerender environment when we read Request data synchronously
const requestStore = workUnitStore;
trackSynchronousRequestDataAccessInDev(requestStore);
}
// In all cases we warn normally
warnForSyncAccess(route, expression);
}
const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev(createCookiesAccessError);
function createCookiesAccessError(route, expression) {
const prefix = route ? `Route "${route}" ` : 'This route ';
return Object.defineProperty(new Error(`${prefix}used ${expression}. ` + `\`cookies()\` should be awaited before using its value. ` + `Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`), "__NEXT_ERROR_CODE", {
value: "E223",
enumerable: false,
configurable: true
});
}
function polyfilledResponseCookiesIterator() {
return this.getAll().map((c)=>[
c.name,
c
]).values();
}
function polyfilledResponseCookiesClear(returnable) {
for (const cookie of this.getAll()){
this.delete(cookie.name);
}
return returnable;
}
//# sourceMappingURL=cookies.js.map

File diff suppressed because one or more lines are too long

204
node_modules/next/dist/esm/server/request/draft-mode.js generated vendored Normal file
View File

@@ -0,0 +1,204 @@
import { getExpectedRequestStore } from '../app-render/work-unit-async-storage.external';
import { workAsyncStorage } from '../app-render/work-async-storage.external';
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external';
import { abortAndThrowOnSynchronousRequestDataAccess, postponeWithTracking, trackSynchronousRequestDataAccessInDev } from '../app-render/dynamic-rendering';
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger';
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout';
import { DynamicServerError } from '../../client/components/hooks-server-context';
export function draftMode() {
const callingExpression = 'draftMode';
const workStore = workAsyncStorage.getStore();
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore) {
if (workUnitStore.type === 'cache' || workUnitStore.type === 'unstable-cache' || workUnitStore.type === 'prerender' || workUnitStore.type === 'prerender-ppr' || workUnitStore.type === 'prerender-legacy') {
// Return empty draft mode
if (process.env.NODE_ENV === 'development' && !(workStore == null ? void 0 : workStore.isPrefetchRequest)) {
const route = workStore == null ? void 0 : workStore.route;
return createExoticDraftModeWithDevWarnings(null, route);
} else {
return createExoticDraftMode(null);
}
}
}
const requestStore = getExpectedRequestStore(callingExpression);
const cachedDraftMode = CachedDraftModes.get(requestStore.draftMode);
if (cachedDraftMode) {
return cachedDraftMode;
}
let promise;
if (process.env.NODE_ENV === 'development' && !(workStore == null ? void 0 : workStore.isPrefetchRequest)) {
const route = workStore == null ? void 0 : workStore.route;
promise = createExoticDraftModeWithDevWarnings(requestStore.draftMode, route);
} else {
promise = createExoticDraftMode(requestStore.draftMode);
}
CachedDraftModes.set(requestStore.draftMode, promise);
return promise;
}
const CachedDraftModes = new WeakMap();
function createExoticDraftMode(underlyingProvider) {
const instance = new DraftMode(underlyingProvider);
const promise = Promise.resolve(instance);
Object.defineProperty(promise, 'isEnabled', {
get () {
return instance.isEnabled;
},
set (newValue) {
Object.defineProperty(promise, 'isEnabled', {
value: newValue,
writable: true,
enumerable: true
});
},
enumerable: true,
configurable: true
});
promise.enable = instance.enable.bind(instance);
promise.disable = instance.disable.bind(instance);
return promise;
}
function createExoticDraftModeWithDevWarnings(underlyingProvider, route) {
const instance = new DraftMode(underlyingProvider);
const promise = Promise.resolve(instance);
Object.defineProperty(promise, 'isEnabled', {
get () {
const expression = '`draftMode().isEnabled`';
syncIODev(route, expression);
return instance.isEnabled;
},
set (newValue) {
Object.defineProperty(promise, 'isEnabled', {
value: newValue,
writable: true,
enumerable: true
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(promise, 'enable', {
value: function get() {
const expression = '`draftMode().enable()`';
syncIODev(route, expression);
return instance.enable.apply(instance, arguments);
}
});
Object.defineProperty(promise, 'disable', {
value: function get() {
const expression = '`draftMode().disable()`';
syncIODev(route, expression);
return instance.disable.apply(instance, arguments);
}
});
return promise;
}
class DraftMode {
constructor(provider){
this._provider = provider;
}
get isEnabled() {
if (this._provider !== null) {
return this._provider.isEnabled;
}
return false;
}
enable() {
// We have a store we want to track dynamic data access to ensure we
// don't statically generate routes that manipulate draft mode.
trackDynamicDraftMode('draftMode().enable()');
if (this._provider !== null) {
this._provider.enable();
}
}
disable() {
trackDynamicDraftMode('draftMode().disable()');
if (this._provider !== null) {
this._provider.disable();
}
}
}
function syncIODev(route, expression) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore && workUnitStore.type === 'request' && workUnitStore.prerenderPhase === true) {
// When we're rendering dynamically in dev we need to advance out of the
// Prerender environment when we read Request data synchronously
const requestStore = workUnitStore;
trackSynchronousRequestDataAccessInDev(requestStore);
}
// In all cases we warn normally
warnForSyncAccess(route, expression);
}
const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev(createDraftModeAccessError);
function createDraftModeAccessError(route, expression) {
const prefix = route ? `Route "${route}" ` : 'This route ';
return Object.defineProperty(new Error(`${prefix}used ${expression}. ` + `\`draftMode()\` should be awaited before using its value. ` + `Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`), "__NEXT_ERROR_CODE", {
value: "E377",
enumerable: false,
configurable: true
});
}
function trackDynamicDraftMode(expression) {
const store = workAsyncStorage.getStore();
const workUnitStore = workUnitAsyncStorage.getStore();
if (store) {
// We have a store we want to track dynamic data access to ensure we
// don't statically generate routes that manipulate draft mode.
if (workUnitStore) {
if (workUnitStore.type === 'cache') {
throw Object.defineProperty(new Error(`Route ${store.route} used "${expression}" inside "use cache". The enabled status of draftMode can be read in caches but you must not enable or disable draftMode inside a cache. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`), "__NEXT_ERROR_CODE", {
value: "E246",
enumerable: false,
configurable: true
});
} else if (workUnitStore.type === 'unstable-cache') {
throw Object.defineProperty(new Error(`Route ${store.route} used "${expression}" inside a function cached with "unstable_cache(...)". The enabled status of draftMode can be read in caches but you must not enable or disable draftMode inside a cache. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache`), "__NEXT_ERROR_CODE", {
value: "E259",
enumerable: false,
configurable: true
});
} else if (workUnitStore.phase === 'after') {
throw Object.defineProperty(new Error(`Route ${store.route} used "${expression}" inside \`after\`. The enabled status of draftMode can be read inside \`after\` but you cannot enable or disable draftMode. See more info here: https://nextjs.org/docs/app/api-reference/functions/after`), "__NEXT_ERROR_CODE", {
value: "E348",
enumerable: false,
configurable: true
});
}
}
if (store.dynamicShouldError) {
throw Object.defineProperty(new StaticGenBailoutError(`Route ${store.route} with \`dynamic = "error"\` couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`), "__NEXT_ERROR_CODE", {
value: "E553",
enumerable: false,
configurable: true
});
}
if (workUnitStore) {
if (workUnitStore.type === 'prerender') {
// dynamicIO Prerender
const error = Object.defineProperty(new Error(`Route ${store.route} used ${expression} without first calling \`await connection()\`. See more info here: https://nextjs.org/docs/messages/next-prerender-sync-headers`), "__NEXT_ERROR_CODE", {
value: "E126",
enumerable: false,
configurable: true
});
abortAndThrowOnSynchronousRequestDataAccess(store.route, expression, error, workUnitStore);
} else if (workUnitStore.type === 'prerender-ppr') {
// PPR Prerender
postponeWithTracking(store.route, expression, workUnitStore.dynamicTracking);
} else if (workUnitStore.type === 'prerender-legacy') {
// legacy Prerender
workUnitStore.revalidate = 0;
const err = Object.defineProperty(new DynamicServerError(`Route ${store.route} couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`), "__NEXT_ERROR_CODE", {
value: "E558",
enumerable: false,
configurable: true
});
store.dynamicUsageDescription = expression;
store.dynamicUsageStack = err.stack;
throw err;
} else if (process.env.NODE_ENV === 'development' && workUnitStore && workUnitStore.type === 'request') {
workUnitStore.usedDynamic = true;
}
}
}
}
//# sourceMappingURL=draft-mode.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,29 @@
import { getRouteMatcher } from '../../shared/lib/router/utils/route-matcher';
import { getRouteRegex } from '../../shared/lib/router/utils/route-regex';
export function getParamKeys(page) {
const pattern = getRouteRegex(page);
const matcher = getRouteMatcher(pattern);
// Get the default list of allowed params.
return Object.keys(matcher(page));
}
export function getFallbackRouteParams(pageOrKeys) {
let keys;
if (typeof pageOrKeys === 'string') {
keys = getParamKeys(pageOrKeys);
} else {
keys = pageOrKeys;
}
// If there are no keys, we can return early.
if (keys.length === 0) return null;
const params = new Map();
// As we're creating unique keys for each of the dynamic route params, we only
// need to generate a unique ID once per request because each of the keys will
// be also be unique.
const uniqueID = Math.random().toString(16).slice(2);
for (const key of keys){
params.set(key, `%%drp:${key}:${uniqueID}%%`);
}
return params;
}
//# sourceMappingURL=fallback-params.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/request/fallback-params.ts"],"sourcesContent":["import { getRouteMatcher } from '../../shared/lib/router/utils/route-matcher'\nimport { getRouteRegex } from '../../shared/lib/router/utils/route-regex'\n\nexport type FallbackRouteParams = ReadonlyMap<string, string>\n\nexport function getParamKeys(page: string) {\n const pattern = getRouteRegex(page)\n const matcher = getRouteMatcher(pattern)\n\n // Get the default list of allowed params.\n return Object.keys(matcher(page))\n}\n\nexport function getFallbackRouteParams(\n pageOrKeys: string | readonly string[]\n): FallbackRouteParams | null {\n let keys: readonly string[]\n if (typeof pageOrKeys === 'string') {\n keys = getParamKeys(pageOrKeys)\n } else {\n keys = pageOrKeys\n }\n\n // If there are no keys, we can return early.\n if (keys.length === 0) return null\n\n const params = new Map<string, string>()\n\n // As we're creating unique keys for each of the dynamic route params, we only\n // need to generate a unique ID once per request because each of the keys will\n // be also be unique.\n const uniqueID = Math.random().toString(16).slice(2)\n\n for (const key of keys) {\n params.set(key, `%%drp:${key}:${uniqueID}%%`)\n }\n\n return params\n}\n"],"names":["getRouteMatcher","getRouteRegex","getParamKeys","page","pattern","matcher","Object","keys","getFallbackRouteParams","pageOrKeys","length","params","Map","uniqueID","Math","random","toString","slice","key","set"],"mappings":"AAAA,SAASA,eAAe,QAAQ,8CAA6C;AAC7E,SAASC,aAAa,QAAQ,4CAA2C;AAIzE,OAAO,SAASC,aAAaC,IAAY;IACvC,MAAMC,UAAUH,cAAcE;IAC9B,MAAME,UAAUL,gBAAgBI;IAEhC,0CAA0C;IAC1C,OAAOE,OAAOC,IAAI,CAACF,QAAQF;AAC7B;AAEA,OAAO,SAASK,uBACdC,UAAsC;IAEtC,IAAIF;IACJ,IAAI,OAAOE,eAAe,UAAU;QAClCF,OAAOL,aAAaO;IACtB,OAAO;QACLF,OAAOE;IACT;IAEA,6CAA6C;IAC7C,IAAIF,KAAKG,MAAM,KAAK,GAAG,OAAO;IAE9B,MAAMC,SAAS,IAAIC;IAEnB,8EAA8E;IAC9E,8EAA8E;IAC9E,qBAAqB;IACrB,MAAMC,WAAWC,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,KAAK,CAAC;IAElD,KAAK,MAAMC,OAAOX,KAAM;QACtBI,OAAOQ,GAAG,CAACD,KAAK,CAAC,MAAM,EAAEA,IAAI,CAAC,EAAEL,SAAS,EAAE,CAAC;IAC9C;IAEA,OAAOF;AACT"}

334
node_modules/next/dist/esm/server/request/headers.js generated vendored Normal file
View File

@@ -0,0 +1,334 @@
import { HeadersAdapter } from '../web/spec-extension/adapters/headers';
import { workAsyncStorage } from '../app-render/work-async-storage.external';
import { getExpectedRequestStore } from '../app-render/work-unit-async-storage.external';
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external';
import { postponeWithTracking, abortAndThrowOnSynchronousRequestDataAccess, throwToInterruptStaticGeneration, trackDynamicDataInDynamicRender, trackSynchronousRequestDataAccessInDev } from '../app-render/dynamic-rendering';
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout';
import { makeHangingPromise } from '../dynamic-rendering-utils';
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger';
import { scheduleImmediate } from '../../lib/scheduler';
import { isRequestAPICallableInsideAfter } from './utils';
/**
* This function allows you to read the HTTP incoming request headers in
* [Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components),
* [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations),
* [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) and
* [Middleware](https://nextjs.org/docs/app/building-your-application/routing/middleware).
*
* Read more: [Next.js Docs: `headers`](https://nextjs.org/docs/app/api-reference/functions/headers)
*/ export function headers() {
const workStore = workAsyncStorage.getStore();
const workUnitStore = workUnitAsyncStorage.getStore();
if (workStore) {
if (workUnitStore && workUnitStore.phase === 'after' && !isRequestAPICallableInsideAfter()) {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "headers" inside "after(...)". This is not supported. If you need this data inside an "after" callback, use "headers" outside of the callback. See more info here: https://nextjs.org/docs/canary/app/api-reference/functions/after`), "__NEXT_ERROR_CODE", {
value: "E367",
enumerable: false,
configurable: true
});
}
if (workStore.forceStatic) {
// When using forceStatic we override all other logic and always just return an empty
// headers object without tracking
const underlyingHeaders = HeadersAdapter.seal(new Headers({}));
return makeUntrackedExoticHeaders(underlyingHeaders);
}
if (workUnitStore) {
if (workUnitStore.type === 'cache') {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "headers" inside "use cache". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use "headers" outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`), "__NEXT_ERROR_CODE", {
value: "E304",
enumerable: false,
configurable: true
});
} else if (workUnitStore.type === 'unstable-cache') {
throw Object.defineProperty(new Error(`Route ${workStore.route} used "headers" inside a function cached with "unstable_cache(...)". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use "headers" outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache`), "__NEXT_ERROR_CODE", {
value: "E127",
enumerable: false,
configurable: true
});
}
}
if (workStore.dynamicShouldError) {
throw Object.defineProperty(new StaticGenBailoutError(`Route ${workStore.route} with \`dynamic = "error"\` couldn't be rendered statically because it used \`headers\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`), "__NEXT_ERROR_CODE", {
value: "E525",
enumerable: false,
configurable: true
});
}
if (workUnitStore) {
if (workUnitStore.type === 'prerender') {
// dynamicIO Prerender
// We don't track dynamic access here because access will be tracked when you access
// one of the properties of the headers object.
return makeDynamicallyTrackedExoticHeaders(workStore.route, workUnitStore);
} else if (workUnitStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
// We are prerendering with PPR. We need track dynamic access here eagerly
// to keep continuity with how headers has worked in PPR without dynamicIO.
// TODO consider switching the semantic to throw on property access instead
postponeWithTracking(workStore.route, 'headers', workUnitStore.dynamicTracking);
} else if (workUnitStore.type === 'prerender-legacy') {
// Legacy Prerender
// We are in a legacy static generation mode while prerendering
// We track dynamic access here so we don't need to wrap the headers in
// individual property access tracking.
throwToInterruptStaticGeneration('headers', workStore, workUnitStore);
}
}
// We fall through to the dynamic context below but we still track dynamic access
// because in dev we can still error for things like using headers inside a cache context
trackDynamicDataInDynamicRender(workStore, workUnitStore);
}
const requestStore = getExpectedRequestStore('headers');
if (process.env.NODE_ENV === 'development' && !(workStore == null ? void 0 : workStore.isPrefetchRequest)) {
return makeUntrackedExoticHeadersWithDevWarnings(requestStore.headers, workStore == null ? void 0 : workStore.route);
} else {
return makeUntrackedExoticHeaders(requestStore.headers);
}
}
const CachedHeaders = new WeakMap();
function makeDynamicallyTrackedExoticHeaders(route, prerenderStore) {
const cachedHeaders = CachedHeaders.get(prerenderStore);
if (cachedHeaders) {
return cachedHeaders;
}
const promise = makeHangingPromise(prerenderStore.renderSignal, '`headers()`');
CachedHeaders.set(prerenderStore, promise);
Object.defineProperties(promise, {
append: {
value: function append() {
const expression = `\`headers().append(${describeNameArg(arguments[0])}, ...)\``;
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
delete: {
value: function _delete() {
const expression = `\`headers().delete(${describeNameArg(arguments[0])})\``;
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
get: {
value: function get() {
const expression = `\`headers().get(${describeNameArg(arguments[0])})\``;
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
has: {
value: function has() {
const expression = `\`headers().has(${describeNameArg(arguments[0])})\``;
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
set: {
value: function set() {
const expression = `\`headers().set(${describeNameArg(arguments[0])}, ...)\``;
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
getSetCookie: {
value: function getSetCookie() {
const expression = '`headers().getSetCookie()`';
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
forEach: {
value: function forEach() {
const expression = '`headers().forEach(...)`';
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
keys: {
value: function keys() {
const expression = '`headers().keys()`';
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
values: {
value: function values() {
const expression = '`headers().values()`';
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
entries: {
value: function entries() {
const expression = '`headers().entries()`';
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
},
[Symbol.iterator]: {
value: function() {
const expression = '`headers()[Symbol.iterator]()`';
const error = createHeadersAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
}
});
return promise;
}
function makeUntrackedExoticHeaders(underlyingHeaders) {
const cachedHeaders = CachedHeaders.get(underlyingHeaders);
if (cachedHeaders) {
return cachedHeaders;
}
const promise = Promise.resolve(underlyingHeaders);
CachedHeaders.set(underlyingHeaders, promise);
Object.defineProperties(promise, {
append: {
value: underlyingHeaders.append.bind(underlyingHeaders)
},
delete: {
value: underlyingHeaders.delete.bind(underlyingHeaders)
},
get: {
value: underlyingHeaders.get.bind(underlyingHeaders)
},
has: {
value: underlyingHeaders.has.bind(underlyingHeaders)
},
set: {
value: underlyingHeaders.set.bind(underlyingHeaders)
},
getSetCookie: {
value: underlyingHeaders.getSetCookie.bind(underlyingHeaders)
},
forEach: {
value: underlyingHeaders.forEach.bind(underlyingHeaders)
},
keys: {
value: underlyingHeaders.keys.bind(underlyingHeaders)
},
values: {
value: underlyingHeaders.values.bind(underlyingHeaders)
},
entries: {
value: underlyingHeaders.entries.bind(underlyingHeaders)
},
[Symbol.iterator]: {
value: underlyingHeaders[Symbol.iterator].bind(underlyingHeaders)
}
});
return promise;
}
function makeUntrackedExoticHeadersWithDevWarnings(underlyingHeaders, route) {
const cachedHeaders = CachedHeaders.get(underlyingHeaders);
if (cachedHeaders) {
return cachedHeaders;
}
const promise = new Promise((resolve)=>scheduleImmediate(()=>resolve(underlyingHeaders)));
CachedHeaders.set(underlyingHeaders, promise);
Object.defineProperties(promise, {
append: {
value: function append() {
const expression = `\`headers().append(${describeNameArg(arguments[0])}, ...)\``;
syncIODev(route, expression);
return underlyingHeaders.append.apply(underlyingHeaders, arguments);
}
},
delete: {
value: function _delete() {
const expression = `\`headers().delete(${describeNameArg(arguments[0])})\``;
syncIODev(route, expression);
return underlyingHeaders.delete.apply(underlyingHeaders, arguments);
}
},
get: {
value: function get() {
const expression = `\`headers().get(${describeNameArg(arguments[0])})\``;
syncIODev(route, expression);
return underlyingHeaders.get.apply(underlyingHeaders, arguments);
}
},
has: {
value: function has() {
const expression = `\`headers().has(${describeNameArg(arguments[0])})\``;
syncIODev(route, expression);
return underlyingHeaders.has.apply(underlyingHeaders, arguments);
}
},
set: {
value: function set() {
const expression = `\`headers().set(${describeNameArg(arguments[0])}, ...)\``;
syncIODev(route, expression);
return underlyingHeaders.set.apply(underlyingHeaders, arguments);
}
},
getSetCookie: {
value: function getSetCookie() {
const expression = '`headers().getSetCookie()`';
syncIODev(route, expression);
return underlyingHeaders.getSetCookie.apply(underlyingHeaders, arguments);
}
},
forEach: {
value: function forEach() {
const expression = '`headers().forEach(...)`';
syncIODev(route, expression);
return underlyingHeaders.forEach.apply(underlyingHeaders, arguments);
}
},
keys: {
value: function keys() {
const expression = '`headers().keys()`';
syncIODev(route, expression);
return underlyingHeaders.keys.apply(underlyingHeaders, arguments);
}
},
values: {
value: function values() {
const expression = '`headers().values()`';
syncIODev(route, expression);
return underlyingHeaders.values.apply(underlyingHeaders, arguments);
}
},
entries: {
value: function entries() {
const expression = '`headers().entries()`';
syncIODev(route, expression);
return underlyingHeaders.entries.apply(underlyingHeaders, arguments);
}
},
[Symbol.iterator]: {
value: function() {
const expression = '`...headers()` or similar iteration';
syncIODev(route, expression);
return underlyingHeaders[Symbol.iterator].apply(underlyingHeaders, arguments);
}
}
});
return promise;
}
function describeNameArg(arg) {
return typeof arg === 'string' ? `'${arg}'` : '...';
}
function syncIODev(route, expression) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore && workUnitStore.type === 'request' && workUnitStore.prerenderPhase === true) {
// When we're rendering dynamically in dev we need to advance out of the
// Prerender environment when we read Request data synchronously
const requestStore = workUnitStore;
trackSynchronousRequestDataAccessInDev(requestStore);
}
// In all cases we warn normally
warnForSyncAccess(route, expression);
}
const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev(createHeadersAccessError);
function createHeadersAccessError(route, expression) {
const prefix = route ? `Route "${route}" ` : 'This route ';
return Object.defineProperty(new Error(`${prefix}used ${expression}. ` + `\`headers()\` should be awaited before using its value. ` + `Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`), "__NEXT_ERROR_CODE", {
value: "E277",
enumerable: false,
configurable: true
});
}
//# sourceMappingURL=headers.js.map

File diff suppressed because one or more lines are too long

334
node_modules/next/dist/esm/server/request/params.js generated vendored Normal file
View File

@@ -0,0 +1,334 @@
import { ReflectAdapter } from '../web/spec-extension/adapters/reflect';
import { abortAndThrowOnSynchronousRequestDataAccess, throwToInterruptStaticGeneration, postponeWithTracking, trackSynchronousRequestDataAccessInDev } from '../app-render/dynamic-rendering';
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external';
import { InvariantError } from '../../shared/lib/invariant-error';
import { describeStringPropertyAccess, wellKnownProperties } from '../../shared/lib/utils/reflect-utils';
import { makeHangingPromise } from '../dynamic-rendering-utils';
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger';
import { scheduleImmediate } from '../../lib/scheduler';
export function createParamsFromClient(underlyingParams, workStore) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore) {
switch(workUnitStore.type){
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
return createPrerenderParams(underlyingParams, workStore, workUnitStore);
default:
}
}
return createRenderParams(underlyingParams, workStore);
}
export const createServerParamsForMetadata = createServerParamsForServerSegment;
// routes always runs in RSC context so it is equivalent to a Server Page Component
export function createServerParamsForRoute(underlyingParams, workStore) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore) {
switch(workUnitStore.type){
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
return createPrerenderParams(underlyingParams, workStore, workUnitStore);
default:
}
}
return createRenderParams(underlyingParams, workStore);
}
export function createServerParamsForServerSegment(underlyingParams, workStore) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore) {
switch(workUnitStore.type){
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
return createPrerenderParams(underlyingParams, workStore, workUnitStore);
default:
}
}
return createRenderParams(underlyingParams, workStore);
}
export function createPrerenderParamsForClientSegment(underlyingParams, workStore) {
const prerenderStore = workUnitAsyncStorage.getStore();
if (prerenderStore && prerenderStore.type === 'prerender') {
const fallbackParams = workStore.fallbackRouteParams;
if (fallbackParams) {
for(let key in underlyingParams){
if (fallbackParams.has(key)) {
// This params object has one of more fallback params so we need to consider
// the awaiting of this params object "dynamic". Since we are in dynamicIO mode
// we encode this as a promise that never resolves
return makeHangingPromise(prerenderStore.renderSignal, '`params`');
}
}
}
}
// We're prerendering in a mode that does not abort. We resolve the promise without
// any tracking because we're just transporting a value from server to client where the tracking
// will be applied.
return Promise.resolve(underlyingParams);
}
function createPrerenderParams(underlyingParams, workStore, prerenderStore) {
const fallbackParams = workStore.fallbackRouteParams;
if (fallbackParams) {
let hasSomeFallbackParams = false;
for(const key in underlyingParams){
if (fallbackParams.has(key)) {
hasSomeFallbackParams = true;
break;
}
}
if (hasSomeFallbackParams) {
// params need to be treated as dynamic because we have at least one fallback param
if (prerenderStore.type === 'prerender') {
// We are in a dynamicIO (PPR or otherwise) prerender
return makeAbortingExoticParams(underlyingParams, workStore.route, prerenderStore);
}
// remaining cases are prerender-ppr and prerender-legacy
// We aren't in a dynamicIO prerender but we do have fallback params at this
// level so we need to make an erroring exotic params object which will postpone
// if you access the fallback params
return makeErroringExoticParams(underlyingParams, fallbackParams, workStore, prerenderStore);
}
}
// We don't have any fallback params so we have an entirely static safe params object
return makeUntrackedExoticParams(underlyingParams);
}
function createRenderParams(underlyingParams, workStore) {
if (process.env.NODE_ENV === 'development' && !workStore.isPrefetchRequest) {
return makeDynamicallyTrackedExoticParamsWithDevWarnings(underlyingParams, workStore);
} else {
return makeUntrackedExoticParams(underlyingParams);
}
}
const CachedParams = new WeakMap();
function makeAbortingExoticParams(underlyingParams, route, prerenderStore) {
const cachedParams = CachedParams.get(underlyingParams);
if (cachedParams) {
return cachedParams;
}
const promise = makeHangingPromise(prerenderStore.renderSignal, '`params`');
CachedParams.set(underlyingParams, promise);
Object.keys(underlyingParams).forEach((prop)=>{
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
} else {
Object.defineProperty(promise, prop, {
get () {
const expression = describeStringPropertyAccess('params', prop);
const error = createParamsAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
},
set (newValue) {
Object.defineProperty(promise, prop, {
value: newValue,
writable: true,
enumerable: true
});
},
enumerable: true,
configurable: true
});
}
});
return promise;
}
function makeErroringExoticParams(underlyingParams, fallbackParams, workStore, prerenderStore) {
const cachedParams = CachedParams.get(underlyingParams);
if (cachedParams) {
return cachedParams;
}
const augmentedUnderlying = {
...underlyingParams
};
// We don't use makeResolvedReactPromise here because params
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = Promise.resolve(augmentedUnderlying);
CachedParams.set(underlyingParams, promise);
Object.keys(underlyingParams).forEach((prop)=>{
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
} else {
if (fallbackParams.has(prop)) {
Object.defineProperty(augmentedUnderlying, prop, {
get () {
const expression = describeStringPropertyAccess('params', prop);
// In most dynamic APIs we also throw if `dynamic = "error"` however
// for params is only dynamic when we're generating a fallback shell
// and even when `dynamic = "error"` we still support generating dynamic
// fallback shells
// TODO remove this comment when dynamicIO is the default since there
// will be no `dynamic = "error"`
if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
},
enumerable: true
});
Object.defineProperty(promise, prop, {
get () {
const expression = describeStringPropertyAccess('params', prop);
// In most dynamic APIs we also throw if `dynamic = "error"` however
// for params is only dynamic when we're generating a fallback shell
// and even when `dynamic = "error"` we still support generating dynamic
// fallback shells
// TODO remove this comment when dynamicIO is the default since there
// will be no `dynamic = "error"`
if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
},
set (newValue) {
Object.defineProperty(promise, prop, {
value: newValue,
writable: true,
enumerable: true
});
},
enumerable: true,
configurable: true
});
} else {
;
promise[prop] = underlyingParams[prop];
}
}
});
return promise;
}
function makeUntrackedExoticParams(underlyingParams) {
const cachedParams = CachedParams.get(underlyingParams);
if (cachedParams) {
return cachedParams;
}
// We don't use makeResolvedReactPromise here because params
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = Promise.resolve(underlyingParams);
CachedParams.set(underlyingParams, promise);
Object.keys(underlyingParams).forEach((prop)=>{
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
} else {
;
promise[prop] = underlyingParams[prop];
}
});
return promise;
}
function makeDynamicallyTrackedExoticParamsWithDevWarnings(underlyingParams, store) {
const cachedParams = CachedParams.get(underlyingParams);
if (cachedParams) {
return cachedParams;
}
// We don't use makeResolvedReactPromise here because params
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = new Promise((resolve)=>scheduleImmediate(()=>resolve(underlyingParams)));
const proxiedProperties = new Set();
const unproxiedProperties = [];
Object.keys(underlyingParams).forEach((prop)=>{
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
unproxiedProperties.push(prop);
} else {
proxiedProperties.add(prop);
promise[prop] = underlyingParams[prop];
}
});
const proxiedPromise = new Proxy(promise, {
get (target, prop, receiver) {
if (typeof prop === 'string') {
if (// We are accessing a property that was proxied to the promise instance
proxiedProperties.has(prop)) {
const expression = describeStringPropertyAccess('params', prop);
syncIODev(store.route, expression);
}
}
return ReflectAdapter.get(target, prop, receiver);
},
set (target, prop, value, receiver) {
if (typeof prop === 'string') {
proxiedProperties.delete(prop);
}
return ReflectAdapter.set(target, prop, value, receiver);
},
ownKeys (target) {
const expression = '`...params` or similar expression';
syncIODev(store.route, expression, unproxiedProperties);
return Reflect.ownKeys(target);
}
});
CachedParams.set(underlyingParams, proxiedPromise);
return proxiedPromise;
}
function syncIODev(route, expression, missingProperties) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore && workUnitStore.type === 'request' && workUnitStore.prerenderPhase === true) {
// When we're rendering dynamically in dev we need to advance out of the
// Prerender environment when we read Request data synchronously
const requestStore = workUnitStore;
trackSynchronousRequestDataAccessInDev(requestStore);
}
// In all cases we warn normally
if (missingProperties && missingProperties.length > 0) {
warnForIncompleteEnumeration(route, expression, missingProperties);
} else {
warnForSyncAccess(route, expression);
}
}
const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev(createParamsAccessError);
const warnForIncompleteEnumeration = createDedupedByCallsiteServerErrorLoggerDev(createIncompleteEnumerationError);
function createParamsAccessError(route, expression) {
const prefix = route ? `Route "${route}" ` : 'This route ';
return Object.defineProperty(new Error(`${prefix}used ${expression}. ` + `\`params\` should be awaited before using its properties. ` + `Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`), "__NEXT_ERROR_CODE", {
value: "E307",
enumerable: false,
configurable: true
});
}
function createIncompleteEnumerationError(route, expression, missingProperties) {
const prefix = route ? `Route "${route}" ` : 'This route ';
return Object.defineProperty(new Error(`${prefix}used ${expression}. ` + `\`params\` should be awaited before using its properties. ` + `The following properties were not available through enumeration ` + `because they conflict with builtin property names: ` + `${describeListOfPropertyNames(missingProperties)}. ` + `Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`), "__NEXT_ERROR_CODE", {
value: "E482",
enumerable: false,
configurable: true
});
}
function describeListOfPropertyNames(properties) {
switch(properties.length){
case 0:
throw Object.defineProperty(new InvariantError('Expected describeListOfPropertyNames to be called with a non-empty list of strings.'), "__NEXT_ERROR_CODE", {
value: "E531",
enumerable: false,
configurable: true
});
case 1:
return `\`${properties[0]}\``;
case 2:
return `\`${properties[0]}\` and \`${properties[1]}\``;
default:
{
let description = '';
for(let i = 0; i < properties.length - 1; i++){
description += `\`${properties[i]}\`, `;
}
description += `, and \`${properties[properties.length - 1]}\``;
return description;
}
}
}
//# sourceMappingURL=params.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,122 @@
import { InvariantError } from '../../shared/lib/invariant-error';
import { postponeWithTracking, throwToInterruptStaticGeneration } from '../app-render/dynamic-rendering';
import { workAsyncStorage } from '../app-render/work-async-storage.external';
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external';
import { makeHangingPromise } from '../dynamic-rendering-utils';
import { describeStringPropertyAccess, wellKnownProperties } from '../../shared/lib/utils/reflect-utils';
const CachedParams = new WeakMap();
export async function unstable_rootParams() {
const workStore = workAsyncStorage.getStore();
if (!workStore) {
throw Object.defineProperty(new InvariantError('Missing workStore in unstable_rootParams'), "__NEXT_ERROR_CODE", {
value: "E615",
enumerable: false,
configurable: true
});
}
const workUnitStore = workUnitAsyncStorage.getStore();
if (!workUnitStore) {
throw Object.defineProperty(new Error(`Route ${workStore.route} used \`unstable_rootParams()\` in Pages Router. This API is only available within App Router.`), "__NEXT_ERROR_CODE", {
value: "E641",
enumerable: false,
configurable: true
});
}
switch(workUnitStore.type){
case 'unstable-cache':
case 'cache':
{
throw Object.defineProperty(new Error(`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.`), "__NEXT_ERROR_CODE", {
value: "E642",
enumerable: false,
configurable: true
});
}
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
return createPrerenderRootParams(workUnitStore.rootParams, workStore, workUnitStore);
default:
return Promise.resolve(workUnitStore.rootParams);
}
}
function createPrerenderRootParams(underlyingParams, workStore, prerenderStore) {
const fallbackParams = workStore.fallbackRouteParams;
if (fallbackParams) {
let hasSomeFallbackParams = false;
for(const key in underlyingParams){
if (fallbackParams.has(key)) {
hasSomeFallbackParams = true;
break;
}
}
if (hasSomeFallbackParams) {
// params need to be treated as dynamic because we have at least one fallback param
if (prerenderStore.type === 'prerender') {
// We are in a dynamicIO (PPR or otherwise) prerender
const cachedParams = CachedParams.get(underlyingParams);
if (cachedParams) {
return cachedParams;
}
const promise = makeHangingPromise(prerenderStore.renderSignal, '`unstable_rootParams`');
CachedParams.set(underlyingParams, promise);
return promise;
}
// remaining cases are prerender-ppr and prerender-legacy
// We aren't in a dynamicIO prerender but we do have fallback params at this
// level so we need to make an erroring params object which will postpone
// if you access the fallback params
return makeErroringRootParams(underlyingParams, fallbackParams, workStore, prerenderStore);
}
}
// We don't have any fallback params so we have an entirely static safe params object
return Promise.resolve(underlyingParams);
}
function makeErroringRootParams(underlyingParams, fallbackParams, workStore, prerenderStore) {
const cachedParams = CachedParams.get(underlyingParams);
if (cachedParams) {
return cachedParams;
}
const augmentedUnderlying = {
...underlyingParams
};
// We don't use makeResolvedReactPromise here because params
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = Promise.resolve(augmentedUnderlying);
CachedParams.set(underlyingParams, promise);
Object.keys(underlyingParams).forEach((prop)=>{
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
} else {
if (fallbackParams.has(prop)) {
Object.defineProperty(augmentedUnderlying, prop, {
get () {
const expression = describeStringPropertyAccess('unstable_rootParams', prop);
// In most dynamic APIs we also throw if `dynamic = "error"` however
// for params is only dynamic when we're generating a fallback shell
// and even when `dynamic = "error"` we still support generating dynamic
// fallback shells
// TODO remove this comment when dynamicIO is the default since there
// will be no `dynamic = "error"`
if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
},
enumerable: true
});
} else {
;
promise[prop] = underlyingParams[prop];
}
}
});
return promise;
}
//# sourceMappingURL=root-params.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,491 @@
import { ReflectAdapter } from '../web/spec-extension/adapters/reflect';
import { abortAndThrowOnSynchronousRequestDataAccess, throwToInterruptStaticGeneration, postponeWithTracking, trackDynamicDataInDynamicRender, annotateDynamicAccess, trackSynchronousRequestDataAccessInDev } from '../app-render/dynamic-rendering';
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external';
import { InvariantError } from '../../shared/lib/invariant-error';
import { makeHangingPromise } from '../dynamic-rendering-utils';
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger';
import { describeStringPropertyAccess, describeHasCheckingStringProperty, wellKnownProperties } from '../../shared/lib/utils/reflect-utils';
import { throwWithStaticGenerationBailoutErrorWithDynamicError, throwForSearchParamsAccessInUseCache } from './utils';
import { scheduleImmediate } from '../../lib/scheduler';
export function createSearchParamsFromClient(underlyingSearchParams, workStore) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore) {
switch(workUnitStore.type){
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
return createPrerenderSearchParams(workStore, workUnitStore);
default:
}
}
return createRenderSearchParams(underlyingSearchParams, workStore);
}
// generateMetadata always runs in RSC context so it is equivalent to a Server Page Component
export const createServerSearchParamsForMetadata = createServerSearchParamsForServerPage;
export function createServerSearchParamsForServerPage(underlyingSearchParams, workStore) {
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore) {
switch(workUnitStore.type){
case 'prerender':
case 'prerender-ppr':
case 'prerender-legacy':
return createPrerenderSearchParams(workStore, workUnitStore);
default:
}
}
return createRenderSearchParams(underlyingSearchParams, workStore);
}
export function createPrerenderSearchParamsForClientPage(workStore) {
if (workStore.forceStatic) {
// When using forceStatic we override all other logic and always just return an empty
// dictionary object.
return Promise.resolve({});
}
const prerenderStore = workUnitAsyncStorage.getStore();
if (prerenderStore && prerenderStore.type === 'prerender') {
// dynamicIO Prerender
// We're prerendering in a mode that aborts (dynamicIO) and should stall
// the promise to ensure the RSC side is considered dynamic
return makeHangingPromise(prerenderStore.renderSignal, '`searchParams`');
}
// We're prerendering in a mode that does not aborts. We resolve the promise without
// any tracking because we're just transporting a value from server to client where the tracking
// will be applied.
return Promise.resolve({});
}
function createPrerenderSearchParams(workStore, prerenderStore) {
if (workStore.forceStatic) {
// When using forceStatic we override all other logic and always just return an empty
// dictionary object.
return Promise.resolve({});
}
if (prerenderStore.type === 'prerender') {
// We are in a dynamicIO (PPR or otherwise) prerender
return makeAbortingExoticSearchParams(workStore.route, prerenderStore);
}
// The remaining cases are prerender-ppr and prerender-legacy
// We are in a legacy static generation and need to interrupt the prerender
// when search params are accessed.
return makeErroringExoticSearchParams(workStore, prerenderStore);
}
function createRenderSearchParams(underlyingSearchParams, workStore) {
if (workStore.forceStatic) {
// When using forceStatic we override all other logic and always just return an empty
// dictionary object.
return Promise.resolve({});
} else {
if (process.env.NODE_ENV === 'development' && !workStore.isPrefetchRequest) {
return makeDynamicallyTrackedExoticSearchParamsWithDevWarnings(underlyingSearchParams, workStore);
} else {
return makeUntrackedExoticSearchParams(underlyingSearchParams, workStore);
}
}
}
const CachedSearchParams = new WeakMap();
const CachedSearchParamsForUseCache = new WeakMap();
function makeAbortingExoticSearchParams(route, prerenderStore) {
const cachedSearchParams = CachedSearchParams.get(prerenderStore);
if (cachedSearchParams) {
return cachedSearchParams;
}
const promise = makeHangingPromise(prerenderStore.renderSignal, '`searchParams`');
const proxiedPromise = new Proxy(promise, {
get (target, prop, receiver) {
if (Object.hasOwn(promise, prop)) {
// The promise has this property directly. we must return it.
// We know it isn't a dynamic access because it can only be something
// that was previously written to the promise and thus not an underlying searchParam value
return ReflectAdapter.get(target, prop, receiver);
}
switch(prop){
case 'then':
{
const expression = '`await searchParams`, `searchParams.then`, or similar';
annotateDynamicAccess(expression, prerenderStore);
return ReflectAdapter.get(target, prop, receiver);
}
case 'status':
{
const expression = '`use(searchParams)`, `searchParams.status`, or similar';
annotateDynamicAccess(expression, prerenderStore);
return ReflectAdapter.get(target, prop, receiver);
}
default:
{
if (typeof prop === 'string' && !wellKnownProperties.has(prop)) {
const expression = describeStringPropertyAccess('searchParams', prop);
const error = createSearchAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
return ReflectAdapter.get(target, prop, receiver);
}
}
},
has (target, prop) {
// We don't expect key checking to be used except for testing the existence of
// searchParams so we make all has tests trigger dynamic. this means that `promise.then`
// can resolve to the then function on the Promise prototype but 'then' in promise will assume
// you are testing whether the searchParams has a 'then' property.
if (typeof prop === 'string') {
const expression = describeHasCheckingStringProperty('searchParams', prop);
const error = createSearchAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
return ReflectAdapter.has(target, prop);
},
ownKeys () {
const expression = '`{...searchParams}`, `Object.keys(searchParams)`, or similar';
const error = createSearchAccessError(route, expression);
abortAndThrowOnSynchronousRequestDataAccess(route, expression, error, prerenderStore);
}
});
CachedSearchParams.set(prerenderStore, proxiedPromise);
return proxiedPromise;
}
function makeErroringExoticSearchParams(workStore, prerenderStore) {
const cachedSearchParams = CachedSearchParams.get(workStore);
if (cachedSearchParams) {
return cachedSearchParams;
}
const underlyingSearchParams = {};
// For search params we don't construct a ReactPromise because we want to interrupt
// rendering on any property access that was not set from outside and so we only want
// to have properties like value and status if React sets them.
const promise = Promise.resolve(underlyingSearchParams);
const proxiedPromise = new Proxy(promise, {
get (target, prop, receiver) {
if (Object.hasOwn(promise, prop)) {
// The promise has this property directly. we must return it.
// We know it isn't a dynamic access because it can only be something
// that was previously written to the promise and thus not an underlying searchParam value
return ReflectAdapter.get(target, prop, receiver);
}
switch(prop){
case 'then':
{
const expression = '`await searchParams`, `searchParams.then`, or similar';
if (workStore.dynamicShouldError) {
throwWithStaticGenerationBailoutErrorWithDynamicError(workStore.route, expression);
} else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
return;
}
case 'status':
{
const expression = '`use(searchParams)`, `searchParams.status`, or similar';
if (workStore.dynamicShouldError) {
throwWithStaticGenerationBailoutErrorWithDynamicError(workStore.route, expression);
} else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
return;
}
default:
{
if (typeof prop === 'string' && !wellKnownProperties.has(prop)) {
const expression = describeStringPropertyAccess('searchParams', prop);
if (workStore.dynamicShouldError) {
throwWithStaticGenerationBailoutErrorWithDynamicError(workStore.route, expression);
} else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
}
return ReflectAdapter.get(target, prop, receiver);
}
}
},
has (target, prop) {
// We don't expect key checking to be used except for testing the existence of
// searchParams so we make all has tests trigger dynamic. this means that `promise.then`
// can resolve to the then function on the Promise prototype but 'then' in promise will assume
// you are testing whether the searchParams has a 'then' property.
if (typeof prop === 'string') {
const expression = describeHasCheckingStringProperty('searchParams', prop);
if (workStore.dynamicShouldError) {
throwWithStaticGenerationBailoutErrorWithDynamicError(workStore.route, expression);
} else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
return false;
}
return ReflectAdapter.has(target, prop);
},
ownKeys () {
const expression = '`{...searchParams}`, `Object.keys(searchParams)`, or similar';
if (workStore.dynamicShouldError) {
throwWithStaticGenerationBailoutErrorWithDynamicError(workStore.route, expression);
} else if (prerenderStore.type === 'prerender-ppr') {
// PPR Prerender (no dynamicIO)
postponeWithTracking(workStore.route, expression, prerenderStore.dynamicTracking);
} else {
// Legacy Prerender
throwToInterruptStaticGeneration(expression, workStore, prerenderStore);
}
}
});
CachedSearchParams.set(workStore, proxiedPromise);
return proxiedPromise;
}
/**
* This is a variation of `makeErroringExoticSearchParams` that always throws an
* error on access, because accessing searchParams inside of `"use cache"` is
* not allowed.
*/ export function makeErroringExoticSearchParamsForUseCache(workStore) {
const cachedSearchParams = CachedSearchParamsForUseCache.get(workStore);
if (cachedSearchParams) {
return cachedSearchParams;
}
const promise = Promise.resolve({});
const proxiedPromise = new Proxy(promise, {
get (target, prop, receiver) {
if (Object.hasOwn(promise, prop)) {
// The promise has this property directly. we must return it. We know it
// isn't a dynamic access because it can only be something that was
// previously written to the promise and thus not an underlying
// searchParam value
return ReflectAdapter.get(target, prop, receiver);
}
if (typeof prop === 'string' && (prop === 'then' || !wellKnownProperties.has(prop))) {
throwForSearchParamsAccessInUseCache(workStore.route);
}
return ReflectAdapter.get(target, prop, receiver);
},
has (target, prop) {
// We don't expect key checking to be used except for testing the existence of
// searchParams so we make all has tests throw an error. this means that `promise.then`
// can resolve to the then function on the Promise prototype but 'then' in promise will assume
// you are testing whether the searchParams has a 'then' property.
if (typeof prop === 'string' && (prop === 'then' || !wellKnownProperties.has(prop))) {
throwForSearchParamsAccessInUseCache(workStore.route);
}
return ReflectAdapter.has(target, prop);
},
ownKeys () {
throwForSearchParamsAccessInUseCache(workStore.route);
}
});
CachedSearchParamsForUseCache.set(workStore, proxiedPromise);
return proxiedPromise;
}
function makeUntrackedExoticSearchParams(underlyingSearchParams, store) {
const cachedSearchParams = CachedSearchParams.get(underlyingSearchParams);
if (cachedSearchParams) {
return cachedSearchParams;
}
// We don't use makeResolvedReactPromise here because searchParams
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = Promise.resolve(underlyingSearchParams);
CachedSearchParams.set(underlyingSearchParams, promise);
Object.keys(underlyingSearchParams).forEach((prop)=>{
if (!wellKnownProperties.has(prop)) {
Object.defineProperty(promise, prop, {
get () {
const workUnitStore = workUnitAsyncStorage.getStore();
trackDynamicDataInDynamicRender(store, workUnitStore);
return underlyingSearchParams[prop];
},
set (value) {
Object.defineProperty(promise, prop, {
value,
writable: true,
enumerable: true
});
},
enumerable: true,
configurable: true
});
}
});
return promise;
}
function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings(underlyingSearchParams, store) {
const cachedSearchParams = CachedSearchParams.get(underlyingSearchParams);
if (cachedSearchParams) {
return cachedSearchParams;
}
const proxiedProperties = new Set();
const unproxiedProperties = [];
// We have an unfortunate sequence of events that requires this initialization logic. We want to instrument the underlying
// searchParams object to detect if you are accessing values in dev. This is used for warnings and for things like the static prerender
// indicator. However when we pass this proxy to our Promise.resolve() below the VM checks if the resolved value is a promise by looking
// at the `.then` property. To our dynamic tracking logic this is indistinguishable from a `then` searchParam and so we would normally trigger
// dynamic tracking. However we know that this .then is not real dynamic access, it's just how thenables resolve in sequence. So we introduce
// this initialization concept so we omit the dynamic check until after we've constructed our resolved promise.
let promiseInitialized = false;
const proxiedUnderlying = new Proxy(underlyingSearchParams, {
get (target, prop, receiver) {
if (typeof prop === 'string' && promiseInitialized) {
if (store.dynamicShouldError) {
const expression = describeStringPropertyAccess('searchParams', prop);
throwWithStaticGenerationBailoutErrorWithDynamicError(store.route, expression);
}
const workUnitStore = workUnitAsyncStorage.getStore();
trackDynamicDataInDynamicRender(store, workUnitStore);
}
return ReflectAdapter.get(target, prop, receiver);
},
has (target, prop) {
if (typeof prop === 'string') {
if (store.dynamicShouldError) {
const expression = describeHasCheckingStringProperty('searchParams', prop);
throwWithStaticGenerationBailoutErrorWithDynamicError(store.route, expression);
}
}
return Reflect.has(target, prop);
},
ownKeys (target) {
if (store.dynamicShouldError) {
const expression = '`{...searchParams}`, `Object.keys(searchParams)`, or similar';
throwWithStaticGenerationBailoutErrorWithDynamicError(store.route, expression);
}
return Reflect.ownKeys(target);
}
});
// We don't use makeResolvedReactPromise here because searchParams
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
const promise = new Promise((resolve)=>scheduleImmediate(()=>resolve(underlyingSearchParams)));
promise.then(()=>{
promiseInitialized = true;
});
Object.keys(underlyingSearchParams).forEach((prop)=>{
if (wellKnownProperties.has(prop)) {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
unproxiedProperties.push(prop);
} else {
proxiedProperties.add(prop);
Object.defineProperty(promise, prop, {
get () {
return proxiedUnderlying[prop];
},
set (newValue) {
Object.defineProperty(promise, prop, {
value: newValue,
writable: true,
enumerable: true
});
},
enumerable: true,
configurable: true
});
}
});
const proxiedPromise = new Proxy(promise, {
get (target, prop, receiver) {
if (prop === 'then' && store.dynamicShouldError) {
const expression = '`searchParams.then`';
throwWithStaticGenerationBailoutErrorWithDynamicError(store.route, expression);
}
if (typeof prop === 'string') {
if (!wellKnownProperties.has(prop) && (proxiedProperties.has(prop) || // We are accessing a property that doesn't exist on the promise nor
// the underlying searchParams.
Reflect.has(target, prop) === false)) {
const expression = describeStringPropertyAccess('searchParams', prop);
syncIODev(store.route, expression);
}
}
return ReflectAdapter.get(target, prop, receiver);
},
set (target, prop, value, receiver) {
if (typeof prop === 'string') {
proxiedProperties.delete(prop);
}
return Reflect.set(target, prop, value, receiver);
},
has (target, prop) {
if (typeof prop === 'string') {
if (!wellKnownProperties.has(prop) && (proxiedProperties.has(prop) || // We are accessing a property that doesn't exist on the promise nor
// the underlying searchParams.
Reflect.has(target, prop) === false)) {
const expression = describeHasCheckingStringProperty('searchParams', prop);
syncIODev(store.route, expression);
}
}
return Reflect.has(target, prop);
},
ownKeys (target) {
const expression = '`Object.keys(searchParams)` or similar';
syncIODev(store.route, expression, unproxiedProperties);
return Reflect.ownKeys(target);
}
});
CachedSearchParams.set(underlyingSearchParams, proxiedPromise);
return proxiedPromise;
}
function syncIODev(route, expression, missingProperties) {
// In all cases we warn normally
if (missingProperties && missingProperties.length > 0) {
warnForIncompleteEnumeration(route, expression, missingProperties);
} else {
warnForSyncAccess(route, expression);
}
const workUnitStore = workUnitAsyncStorage.getStore();
if (workUnitStore && workUnitStore.type === 'request' && workUnitStore.prerenderPhase === true) {
// When we're rendering dynamically in dev we need to advance out of the
// Prerender environment when we read Request data synchronously
const requestStore = workUnitStore;
trackSynchronousRequestDataAccessInDev(requestStore);
}
}
const warnForSyncAccess = createDedupedByCallsiteServerErrorLoggerDev(createSearchAccessError);
const warnForIncompleteEnumeration = createDedupedByCallsiteServerErrorLoggerDev(createIncompleteEnumerationError);
function createSearchAccessError(route, expression) {
const prefix = route ? `Route "${route}" ` : 'This route ';
return Object.defineProperty(new Error(`${prefix}used ${expression}. ` + `\`searchParams\` should be awaited before using its properties. ` + `Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`), "__NEXT_ERROR_CODE", {
value: "E249",
enumerable: false,
configurable: true
});
}
function createIncompleteEnumerationError(route, expression, missingProperties) {
const prefix = route ? `Route "${route}" ` : 'This route ';
return Object.defineProperty(new Error(`${prefix}used ${expression}. ` + `\`searchParams\` should be awaited before using its properties. ` + `The following properties were not available through enumeration ` + `because they conflict with builtin or well-known property names: ` + `${describeListOfPropertyNames(missingProperties)}. ` + `Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis`), "__NEXT_ERROR_CODE", {
value: "E2",
enumerable: false,
configurable: true
});
}
function describeListOfPropertyNames(properties) {
switch(properties.length){
case 0:
throw Object.defineProperty(new InvariantError('Expected describeListOfPropertyNames to be called with a non-empty list of strings.'), "__NEXT_ERROR_CODE", {
value: "E531",
enumerable: false,
configurable: true
});
case 1:
return `\`${properties[0]}\``;
case 2:
return `\`${properties[0]}\` and \`${properties[1]}\``;
default:
{
let description = '';
for(let i = 0; i < properties.length - 1; i++){
description += `\`${properties[i]}\`, `;
}
description += `, and \`${properties[properties.length - 1]}\``;
return description;
}
}
}
//# sourceMappingURL=search-params.js.map

File diff suppressed because one or more lines are too long

29
node_modules/next/dist/esm/server/request/utils.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout';
import { afterTaskAsyncStorage } from '../app-render/after-task-async-storage.external';
export function throwWithStaticGenerationBailoutError(route, expression) {
throw Object.defineProperty(new StaticGenBailoutError(`Route ${route} couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`), "__NEXT_ERROR_CODE", {
value: "E576",
enumerable: false,
configurable: true
});
}
export function throwWithStaticGenerationBailoutErrorWithDynamicError(route, expression) {
throw Object.defineProperty(new StaticGenBailoutError(`Route ${route} with \`dynamic = "error"\` couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`), "__NEXT_ERROR_CODE", {
value: "E543",
enumerable: false,
configurable: true
});
}
export function throwForSearchParamsAccessInUseCache(route) {
throw Object.defineProperty(new Error(`Route ${route} used "searchParams" inside "use cache". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use "searchParams" outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`), "__NEXT_ERROR_CODE", {
value: "E634",
enumerable: false,
configurable: true
});
}
export function isRequestAPICallableInsideAfter() {
const afterTaskStore = afterTaskAsyncStorage.getStore();
return (afterTaskStore == null ? void 0 : afterTaskStore.rootTaskSpawnPhase) === 'action';
}
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/request/utils.ts"],"sourcesContent":["import { StaticGenBailoutError } from '../../client/components/static-generation-bailout'\nimport { afterTaskAsyncStorage } from '../app-render/after-task-async-storage.external'\n\nexport function throwWithStaticGenerationBailoutError(\n route: string,\n expression: string\n): never {\n throw new StaticGenBailoutError(\n `Route ${route} couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`\n )\n}\n\nexport function throwWithStaticGenerationBailoutErrorWithDynamicError(\n route: string,\n expression: string\n): never {\n throw new StaticGenBailoutError(\n `Route ${route} with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`\n )\n}\n\nexport function throwForSearchParamsAccessInUseCache(route: string): never {\n throw new Error(\n `Route ${route} used \"searchParams\" inside \"use cache\". Accessing Dynamic data sources inside a cache scope is not supported. If you need this data inside a cached function use \"searchParams\" outside of the cached function and pass the required dynamic data in as an argument. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`\n )\n}\n\nexport function isRequestAPICallableInsideAfter() {\n const afterTaskStore = afterTaskAsyncStorage.getStore()\n return afterTaskStore?.rootTaskSpawnPhase === 'action'\n}\n"],"names":["StaticGenBailoutError","afterTaskAsyncStorage","throwWithStaticGenerationBailoutError","route","expression","throwWithStaticGenerationBailoutErrorWithDynamicError","throwForSearchParamsAccessInUseCache","Error","isRequestAPICallableInsideAfter","afterTaskStore","getStore","rootTaskSpawnPhase"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oDAAmD;AACzF,SAASC,qBAAqB,QAAQ,kDAAiD;AAEvF,OAAO,SAASC,sCACdC,KAAa,EACbC,UAAkB;IAElB,MAAM,qBAEL,CAFK,IAAIJ,sBACR,CAAC,MAAM,EAAEG,MAAM,iDAAiD,EAAEC,WAAW,0HAA0H,CAAC,GADpM,qBAAA;eAAA;oBAAA;sBAAA;IAEN;AACF;AAEA,OAAO,SAASC,sDACdF,KAAa,EACbC,UAAkB;IAElB,MAAM,qBAEL,CAFK,IAAIJ,sBACR,CAAC,MAAM,EAAEG,MAAM,4EAA4E,EAAEC,WAAW,0HAA0H,CAAC,GAD/N,qBAAA;eAAA;oBAAA;sBAAA;IAEN;AACF;AAEA,OAAO,SAASE,qCAAqCH,KAAa;IAChE,MAAM,qBAEL,CAFK,IAAII,MACR,CAAC,MAAM,EAAEJ,MAAM,oVAAoV,CAAC,GADhW,qBAAA;eAAA;oBAAA;sBAAA;IAEN;AACF;AAEA,OAAO,SAASK;IACd,MAAMC,iBAAiBR,sBAAsBS,QAAQ;IACrD,OAAOD,CAAAA,kCAAAA,eAAgBE,kBAAkB,MAAK;AAChD"}