Unverified Commit 724c4462 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Support crossOrigin in Turbopack (#61461)

## What?

Implements `crossOrigin` in the React Client Components manifest for
Turbopack. This feature was missing.

Removes the `false` value as it doesn't actually do anything, the
default is no crossorigin property.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-2313
parent d6badf82
...@@ -705,10 +705,7 @@ impl AppEndpoint { ...@@ -705,10 +705,7 @@ impl AppEndpoint {
client_references_chunks, client_references_chunks,
this.app_project.project().client_chunking_context(), this.app_project.project().client_chunking_context(),
ssr_chunking_context, ssr_chunking_context,
this.app_project this.app_project.project().next_config(),
.project()
.next_config()
.computed_asset_prefix(),
runtime, runtime,
); );
server_assets.push(entry_manifest); server_assets.push(entry_manifest);
......
...@@ -100,7 +100,7 @@ pub struct NextConfig { ...@@ -100,7 +100,7 @@ pub struct NextConfig {
pub skip_middleware_url_normalize: Option<bool>, pub skip_middleware_url_normalize: Option<bool>,
pub skip_trailing_slash_redirect: Option<bool>, pub skip_trailing_slash_redirect: Option<bool>,
pub i18n: Option<I18NConfig>, pub i18n: Option<I18NConfig>,
pub cross_origin: Option<String>, pub cross_origin: Option<CrossOriginConfig>,
pub dev_indicators: Option<DevIndicatorsConfig>, pub dev_indicators: Option<DevIndicatorsConfig>,
pub output: Option<OutputType>, pub output: Option<OutputType>,
pub analytics_id: Option<String>, pub analytics_id: Option<String>,
...@@ -140,6 +140,13 @@ pub struct NextConfig { ...@@ -140,6 +140,13 @@ pub struct NextConfig {
webpack: Option<serde_json::Value>, webpack: Option<serde_json::Value>,
} }
#[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)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct AmpConfig { struct AmpConfig {
......
...@@ -16,6 +16,7 @@ use super::{ClientReferenceManifest, ManifestNode, ManifestNodeEntry, ModuleId}; ...@@ -16,6 +16,7 @@ use super::{ClientReferenceManifest, ManifestNode, ManifestNodeEntry, ModuleId};
use crate::{ use crate::{
next_app::ClientReferencesChunks, next_app::ClientReferencesChunks,
next_client_reference::{ClientReferenceGraphResult, ClientReferenceType}, next_client_reference::{ClientReferenceGraphResult, ClientReferenceType},
next_config::NextConfig,
util::NextRuntime, util::NextRuntime,
}; };
...@@ -30,16 +31,22 @@ impl ClientReferenceManifest { ...@@ -30,16 +31,22 @@ impl ClientReferenceManifest {
client_references_chunks: Vc<ClientReferencesChunks>, client_references_chunks: Vc<ClientReferencesChunks>,
client_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>, client_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
ssr_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>, ssr_chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
asset_prefix: Vc<Option<String>>, next_config: Vc<NextConfig>,
runtime: NextRuntime, runtime: NextRuntime,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<Vc<Box<dyn OutputAsset>>> {
let mut entry_manifest: ClientReferenceManifest = Default::default(); 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? .await?
.as_ref() .as_ref()
.map(|p| p.to_owned()) .map(|p| p.to_owned())
.unwrap_or_default(); .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_references_chunks = client_references_chunks.await?;
let client_relative_path = client_relative_path.await?; let client_relative_path = client_relative_path.await?;
let node_root_ref = node_root.await?; let node_root_ref = node_root.await?;
......
...@@ -8,7 +8,7 @@ use indexmap::IndexSet; ...@@ -8,7 +8,7 @@ use indexmap::IndexSet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, TaskInput}; use turbo_tasks::{trace::TraceRawVcs, TaskInput};
use crate::next_config::Rewrites; use crate::next_config::{CrossOriginConfig, Rewrites};
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
pub struct PagesManifest { pub struct PagesManifest {
...@@ -247,7 +247,7 @@ pub struct ClientReferenceManifest { ...@@ -247,7 +247,7 @@ pub struct ClientReferenceManifest {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ModuleLoading { pub struct ModuleLoading {
pub prefix: String, pub prefix: String,
pub cross_origin: Option<String>, pub cross_origin: Option<CrossOriginConfig>,
} }
#[derive(Serialize, Default, Debug, Clone)] #[derive(Serialize, Default, Debug, Clone)]
......
...@@ -198,11 +198,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -198,11 +198,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
compress: z.boolean().optional(), compress: z.boolean().optional(),
configOrigin: z.string().optional(), configOrigin: z.string().optional(),
crossOrigin: z crossOrigin: z
.union([ .union([z.literal('anonymous'), z.literal('use-credentials')])
z.literal(false),
z.literal('anonymous'),
z.literal('use-credentials'),
])
.optional(), .optional(),
devIndicators: z devIndicators: z
.object({ .object({
......
...@@ -676,7 +676,7 @@ export interface NextConfig extends Record<string, any> { ...@@ -676,7 +676,7 @@ export interface NextConfig extends Record<string, any> {
* *
* @see [`crossorigin` attribute documentation](https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin) * @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 * Use [SWC compiler](https://swc.rs) to minify the generated JavaScript
......
...@@ -2427,10 +2427,10 @@ ...@@ -2427,10 +2427,10 @@
"runtimeError": false "runtimeError": false
}, },
"test/e2e/app-dir/app-config-crossorigin/index.test.ts": { "test/e2e/app-dir/app-config-crossorigin/index.test.ts": {
"passed": [], "passed": [
"failed": [
"app dir - crossOrigin config should render correctly with assetPrefix: \"/\"" "app dir - crossOrigin config should render correctly with assetPrefix: \"/\""
], ],
"failed": [],
"pending": [], "pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment