diff --git a/packages/next-swc/crates/next-api/src/app.rs b/packages/next-swc/crates/next-api/src/app.rs index 4cf18f9d74fca..e77a2a250ebaa 100644 --- a/packages/next-swc/crates/next-api/src/app.rs +++ b/packages/next-swc/crates/next-api/src/app.rs @@ -705,10 +705,7 @@ impl AppEndpoint { client_references_chunks, this.app_project.project().client_chunking_context(), ssr_chunking_context, - this.app_project - .project() - .next_config() - .computed_asset_prefix(), + this.app_project.project().next_config(), runtime, ); server_assets.push(entry_manifest); diff --git a/packages/next-swc/crates/next-core/src/next_config.rs b/packages/next-swc/crates/next-core/src/next_config.rs index 171363dcc67e7..40df34788c533 100644 --- a/packages/next-swc/crates/next-core/src/next_config.rs +++ b/packages/next-swc/crates/next-core/src/next_config.rs @@ -100,7 +100,7 @@ pub struct NextConfig { pub skip_middleware_url_normalize: Option, pub skip_trailing_slash_redirect: Option, pub i18n: Option, - pub cross_origin: Option, + pub cross_origin: Option, pub dev_indicators: Option, pub output: Option, pub analytics_id: Option, @@ -140,6 +140,13 @@ pub struct NextConfig { webpack: Option, } +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)] +#[serde(rename_all = "kebab-case")] +pub enum CrossOriginConfig { + Anonymous, + UseCredentials, +} + #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs)] #[serde(rename_all = "camelCase")] struct AmpConfig { diff --git a/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs b/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs index c6f0a42eb3061..fae5d7ee4498e 100644 --- a/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs +++ b/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs @@ -16,6 +16,7 @@ use super::{ClientReferenceManifest, ManifestNode, ManifestNodeEntry, ModuleId}; use crate::{ next_app::ClientReferencesChunks, next_client_reference::{ClientReferenceGraphResult, ClientReferenceType}, + next_config::NextConfig, util::NextRuntime, }; @@ -30,16 +31,22 @@ impl ClientReferenceManifest { client_references_chunks: Vc, client_chunking_context: Vc>, ssr_chunking_context: Vc>, - asset_prefix: Vc>, + next_config: Vc, runtime: NextRuntime, ) -> Result>> { let mut entry_manifest: ClientReferenceManifest = Default::default(); - entry_manifest.module_loading.prefix = asset_prefix + entry_manifest.module_loading.prefix = next_config + .computed_asset_prefix() .await? .as_ref() .map(|p| p.to_owned()) .unwrap_or_default(); - entry_manifest.module_loading.cross_origin = None; + + entry_manifest.module_loading.cross_origin = next_config + .await? + .cross_origin + .as_ref() + .map(|p| p.to_owned()); let client_references_chunks = client_references_chunks.await?; let client_relative_path = client_relative_path.await?; let node_root_ref = node_root.await?; diff --git a/packages/next-swc/crates/next-core/src/next_manifests/mod.rs b/packages/next-swc/crates/next-core/src/next_manifests/mod.rs index ba71f122bead4..157fd5105dfab 100644 --- a/packages/next-swc/crates/next-core/src/next_manifests/mod.rs +++ b/packages/next-swc/crates/next-core/src/next_manifests/mod.rs @@ -8,7 +8,7 @@ use indexmap::IndexSet; use serde::{Deserialize, Serialize}; use turbo_tasks::{trace::TraceRawVcs, TaskInput}; -use crate::next_config::Rewrites; +use crate::next_config::{CrossOriginConfig, Rewrites}; #[derive(Serialize, Default, Debug)] pub struct PagesManifest { @@ -247,7 +247,7 @@ pub struct ClientReferenceManifest { #[serde(rename_all = "camelCase")] pub struct ModuleLoading { pub prefix: String, - pub cross_origin: Option, + pub cross_origin: Option, } #[derive(Serialize, Default, Debug, Clone)] diff --git a/packages/next/src/server/config-schema.ts b/packages/next/src/server/config-schema.ts index d7f2df93c01e6..9d270c1a2a128 100644 --- a/packages/next/src/server/config-schema.ts +++ b/packages/next/src/server/config-schema.ts @@ -198,11 +198,7 @@ export const configSchema: zod.ZodType = z.lazy(() => compress: z.boolean().optional(), configOrigin: z.string().optional(), crossOrigin: z - .union([ - z.literal(false), - z.literal('anonymous'), - z.literal('use-credentials'), - ]) + .union([z.literal('anonymous'), z.literal('use-credentials')]) .optional(), devIndicators: z .object({ diff --git a/packages/next/src/server/config-shared.ts b/packages/next/src/server/config-shared.ts index 5f6c881ffb7fe..bf7c0162ef3d2 100644 --- a/packages/next/src/server/config-shared.ts +++ b/packages/next/src/server/config-shared.ts @@ -676,7 +676,7 @@ export interface NextConfig extends Record { * * @see [`crossorigin` attribute documentation](https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin) */ - crossOrigin?: false | 'anonymous' | 'use-credentials' + crossOrigin?: 'anonymous' | 'use-credentials' /** * Use [SWC compiler](https://swc.rs) to minify the generated JavaScript diff --git a/test/turbopack-tests-manifest.json b/test/turbopack-tests-manifest.json index 6488d0acb09bf..df506dd7d343d 100644 --- a/test/turbopack-tests-manifest.json +++ b/test/turbopack-tests-manifest.json @@ -2427,10 +2427,10 @@ "runtimeError": false }, "test/e2e/app-dir/app-config-crossorigin/index.test.ts": { - "passed": [], - "failed": [ + "passed": [ "app dir - crossOrigin config should render correctly with assetPrefix: \"/\"" ], + "failed": [], "pending": [], "flakey": [], "runtimeError": false