File size: 9,655 Bytes
4514571 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | diff --git a/crates/next-core/src/browser_variant_modules.rs b/crates/next-core/src/browser_variant_modules.rs
index 1e1b9295b4..133ef25ace 100644
--- a/crates/next-core/src/browser_variant_modules.rs
+++ b/crates/next-core/src/browser_variant_modules.rs
@@ -11,6 +11,8 @@
#[rustfmt::skip]
pub static BROWSER_VARIANT_MODULES: &[&str] = &[
"client/components/client-boundary-params",
+ "client/components/instant-samples",
+ "client/components/instant-validation/impl",
"client/components/navigation-dynamic-rendering",
"client/components/server-async-storage",
"client/components/unstable-rethrow",
diff --git a/packages/next/src/build/browser-variant-modules.ts b/packages/next/src/build/browser-variant-modules.ts
index bf7685e857..45563cf715 100644
--- a/packages/next/src/build/browser-variant-modules.ts
+++ b/packages/next/src/build/browser-variant-modules.ts
@@ -7,6 +7,8 @@
// `packages/next/dist` (extension omitted).
export const browserVariantModules = [
'client/components/client-boundary-params',
+ 'client/components/instant-samples',
+ 'client/components/instant-validation/impl',
'client/components/navigation-dynamic-rendering',
'client/components/server-async-storage',
'client/components/unstable-rethrow',
diff --git a/packages/next/src/client/components/instant-samples.browser.ts b/packages/next/src/client/components/instant-samples.browser.ts
new file mode 100644
index 0000000000..35c2fbf65a
--- /dev/null
+++ b/packages/next/src/client/components/instant-samples.browser.ts
@@ -0,0 +1,3 @@
+export const instrumentParamsForClientValidation = undefined
+export const expectCompleteParamsInClientValidation = undefined
+export const instrumentSearchParamsForClientValidation = undefined
diff --git a/packages/next/src/server/app-render/instant-validation/instant-samples-client.ts b/packages/next/src/client/components/instant-samples.ts
similarity index 88%
rename from packages/next/src/server/app-render/instant-validation/instant-samples-client.ts
rename to packages/next/src/client/components/instant-samples.ts
index 15101787cb..7bd30ba8b1 100644
--- a/packages/next/src/server/app-render/instant-validation/instant-samples-client.ts
+++ b/packages/next/src/client/components/instant-samples.ts
@@ -1,13 +1,13 @@
-import type { Params } from '../../request/params'
-import type { ReadonlyURLSearchParams } from '../../../client/components/readonly-url-search-params'
-import { workUnitAsyncStorage } from '../work-unit-async-storage.external'
-import { workAsyncStorage } from '../work-async-storage.external'
+import type { Params } from '../../server/request/params'
+import type { ReadonlyURLSearchParams } from './readonly-url-search-params'
+import { workUnitAsyncStorage } from '../../server/app-render/work-unit-async-storage.external'
+import { workAsyncStorage } from '../../server/app-render/work-async-storage.external'
import {
createExhaustiveParamsProxy,
createExhaustiveURLSearchParamsProxy,
trackMissingSampleErrorAndThrow,
-} from './instant-samples'
-import { InstantValidationError } from './instant-validation-error'
+} from '../../server/app-render/instant-validation/instant-samples'
+import { InstantValidationError } from '../../server/app-render/instant-validation/instant-validation-error'
export function instrumentParamsForClientValidation<TPArams extends Params>(
underlyingParams: TPArams
diff --git a/packages/next/src/client/components/instant-validation/boundary.tsx b/packages/next/src/client/components/instant-validation/boundary.tsx
index cf39318c3a..8ed8ccd7fe 100644
--- a/packages/next/src/client/components/instant-validation/boundary.tsx
+++ b/packages/next/src/client/components/instant-validation/boundary.tsx
@@ -1,29 +1,9 @@
'use client'
-
-// This facade ensures that the boundary code is DCE'd in browser bundles.
-//
-// It also exists to satisfy `browser-chunks.test.ts`, which looks for
-// references to code in `packages/next/src/server` in browser bundles and errors if it finds any.
-// A "use client" module seems to always have always have an entry in the browser bundle,
-// so this module cannot be colocated with the rest of the instant validation code,
-// because it ends up looking like it's importing server code in the browser
-// even though all the server code inside is actually DCE'd.
-
-const {
- InstantValidationBoundaryContext,
- PlaceValidationBoundaryBelowThisLevel,
- RenderValidationBoundaryAtThisLevel,
- SlotMarker,
-} =
- typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS
- ? // TODO(browser-variant): migrate to a .ts/.browser.ts split so the browser bundle drops the server branch; see scripts/generate-browser-variant-aliases.mjs
- // ast-grep-ignore: no-typeof-window-require-tsx
- (require('../../../server/app-render/instant-validation/boundary-impl') as typeof import('../../../server/app-render/instant-validation/boundary-impl'))
- : ({} as typeof import('../../../server/app-render/instant-validation/boundary-impl'))
-
+// We can't fork a `use client` boundary based on node-client vs browser-client.
+// We need to fork one level deeper.
export {
InstantValidationBoundaryContext,
PlaceValidationBoundaryBelowThisLevel,
RenderValidationBoundaryAtThisLevel,
SlotMarker,
-}
+} from './impl'
diff --git a/packages/next/src/client/components/instant-validation/impl.browser.tsx b/packages/next/src/client/components/instant-validation/impl.browser.tsx
new file mode 100644
index 0000000000..fad4049807
--- /dev/null
+++ b/packages/next/src/client/components/instant-validation/impl.browser.tsx
@@ -0,0 +1,4 @@
+export const InstantValidationBoundaryContext = null
+export const PlaceValidationBoundaryBelowThisLevel = null
+export const RenderValidationBoundaryAtThisLevel = null
+export const SlotMarker = null
diff --git a/packages/next/src/client/components/instant-validation/impl.tsx b/packages/next/src/client/components/instant-validation/impl.tsx
new file mode 100644
index 0000000000..62e291f209
--- /dev/null
+++ b/packages/next/src/client/components/instant-validation/impl.tsx
@@ -0,0 +1,6 @@
+export {
+ InstantValidationBoundaryContext,
+ PlaceValidationBoundaryBelowThisLevel,
+ RenderValidationBoundaryAtThisLevel,
+ SlotMarker,
+} from '../../../server/app-render/instant-validation/boundary-impl'
diff --git a/packages/next/src/client/components/layout-router.tsx b/packages/next/src/client/components/layout-router.tsx
index efdd8d9187..52019013c5 100644
--- a/packages/next/src/client/components/layout-router.tsx
+++ b/packages/next/src/client/components/layout-router.tsx
@@ -33,6 +33,10 @@ import { ErrorBoundary } from './error-boundary'
import { disableSmoothScrollDuringRouteTransition } from '../../shared/lib/router/utils/disable-smooth-scroll'
import { RedirectBoundary } from './redirect-boundary'
import { HTTPAccessFallbackBoundary } from './http-access-fallback/error-boundary'
+import {
+ InstantValidationBoundaryContext,
+ RenderValidationBoundaryAtThisLevel,
+} from './instant-validation/boundary'
import { createRouterCacheKey } from './router-reducer/create-router-cache-key'
import {
useRouterBFCache,
@@ -670,10 +674,6 @@ export default function OuterLayoutRouter({
let maybeValidationBoundaryId: string | null = null
if (typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS) {
- const { InstantValidationBoundaryContext } =
- // TODO(browser-variant): migrate to a .ts/.browser.ts split so the browser bundle drops the server branch; see scripts/generate-browser-variant-aliases.mjs
- // ast-grep-ignore: no-typeof-window-require-tsx
- require('./instant-validation/boundary') as typeof import('./instant-validation/boundary')
maybeValidationBoundaryId = use(InstantValidationBoundaryContext)
}
@@ -812,10 +812,6 @@ export default function OuterLayoutRouter({
process.env.__NEXT_CACHE_COMPONENTS &&
typeof maybeValidationBoundaryId === 'string'
) {
- const { RenderValidationBoundaryAtThisLevel } =
- // TODO(browser-variant): migrate to a .ts/.browser.ts split so the browser bundle drops the server branch; see scripts/generate-browser-variant-aliases.mjs
- // ast-grep-ignore: no-typeof-window-require-tsx
- require('./instant-validation/boundary') as typeof import('./instant-validation/boundary')
templateValue = (
<RenderValidationBoundaryAtThisLevel id={maybeValidationBoundaryId}>
{templateValue}
diff --git a/packages/next/src/client/components/navigation.ts b/packages/next/src/client/components/navigation.ts
index 0c7dc84d32..2e1df203d8 100644
--- a/packages/next/src/client/components/navigation.ts
+++ b/packages/next/src/client/components/navigation.ts
@@ -27,12 +27,9 @@ const {
instrumentParamsForClientValidation,
instrumentSearchParamsForClientValidation,
expectCompleteParamsInClientValidation,
-} =
- typeof window === 'undefined' && process.env.__NEXT_CACHE_COMPONENTS
- ? // TODO(browser-variant): migrate to a .ts/.browser.ts split so the browser bundle drops the server branch; see scripts/generate-browser-variant-aliases.mjs
- // ast-grep-ignore: no-typeof-window-require
- (require('../../server/app-render/instant-validation/instant-samples-client') as typeof import('../../server/app-render/instant-validation/instant-samples-client'))
- : {}
+} = process.env.__NEXT_CACHE_COMPONENTS
+ ? (require('./instant-samples') as typeof import('./instant-samples'))
+ : {}
/**
* A [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components) hook
|