Commit 74f8ff88 authored by Tobias Koppers's avatar Tobias Koppers

Restore cross_origin support lost in rebase conflict resolution

The rebase conflict incorrectly replaced cross_origin with esm_chunks
in BrowserChunkingContext, dropping the cross_origin feature added by
#92070. Restore both fields and update snapshots to include CROSS_ORIGIN.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent f4bf0963
...@@ -8,9 +8,9 @@ use turbopack_core::{ ...@@ -8,9 +8,9 @@ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ chunk::{
AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkableModule, AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkableModule,
ChunkingConfig, ChunkingConfigs, ChunkingContext, ContentHashing, EntryChunkGroupResult, ChunkingConfig, ChunkingConfigs, ChunkingContext, ContentHashing, CrossOrigin,
EvaluatableAsset, EvaluatableAssets, MinifyType, SourceMapSourceType, SourceMapsType, EntryChunkGroupResult, EvaluatableAsset, EvaluatableAssets, MinifyType,
UnusedReferences, UrlBehavior, SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
availability_info::AvailabilityInfo, availability_info::AvailabilityInfo,
chunk_group::{MakeChunkGroupResult, make_chunk_group}, chunk_group::{MakeChunkGroupResult, make_chunk_group},
chunk_id_strategy::ModuleIdStrategy, chunk_id_strategy::ModuleIdStrategy,
...@@ -224,6 +224,11 @@ impl BrowserChunkingContextBuilder { ...@@ -224,6 +224,11 @@ impl BrowserChunkingContextBuilder {
self self
} }
pub fn cross_origin(mut self, cross_origin: CrossOrigin) -> Self {
self.chunking_context.cross_origin = cross_origin;
self
}
pub fn esm_chunks(mut self, esm_chunks: bool) -> Self { pub fn esm_chunks(mut self, esm_chunks: bool) -> Self {
self.chunking_context.esm_chunks = esm_chunks; self.chunking_context.esm_chunks = esm_chunks;
self self
...@@ -327,6 +332,8 @@ pub struct BrowserChunkingContext { ...@@ -327,6 +332,8 @@ pub struct BrowserChunkingContext {
chunk_loading_global: Option<RcStr>, chunk_loading_global: Option<RcStr>,
/// Salt mixed into chunk and asset content hashes. Empty string means no salt. /// Salt mixed into chunk and asset content hashes. Empty string means no salt.
hash_salt: ResolvedVc<RcStr>, hash_salt: ResolvedVc<RcStr>,
/// The crossorigin mode for dynamically loaded chunks.
cross_origin: CrossOrigin,
/// Emit chunks as ES modules (`export default [factories...]`) instead of /// Emit chunks as ES modules (`export default [factories...]`) instead of
/// `globalThis["TURBOPACK"].push([...])`. The runtime loads them via `import()`. /// `globalThis["TURBOPACK"].push([...])`. The runtime loads them via `import()`.
/// Requires `current_chunk_method` to be set to `ImportMetaUrl` when used. /// Requires `current_chunk_method` to be set to `ImportMetaUrl` when used.
...@@ -384,6 +391,7 @@ impl BrowserChunkingContext { ...@@ -384,6 +391,7 @@ impl BrowserChunkingContext {
worker_forwarded_globals: vec![], worker_forwarded_globals: vec![],
chunk_loading_global: Default::default(), chunk_loading_global: Default::default(),
hash_salt: ResolvedVc::cell(RcStr::default()), hash_salt: ResolvedVc::cell(RcStr::default()),
cross_origin: Default::default(),
esm_chunks: false, esm_chunks: false,
}, },
} }
...@@ -515,6 +523,12 @@ impl BrowserChunkingContext { ...@@ -515,6 +523,12 @@ impl BrowserChunkingContext {
) )
} }
/// Returns the crossorigin mode for dynamically loaded chunks.
#[turbo_tasks::function]
pub fn cross_origin(&self) -> Vc<CrossOrigin> {
self.cross_origin.cell()
}
/// Returns whether chunks are emitted as ES modules. /// Returns whether chunks are emitted as ES modules.
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn esm_chunks(&self) -> Vc<bool> { pub fn esm_chunks(&self) -> Vc<bool> {
......
...@@ -201,6 +201,7 @@ impl EcmascriptBrowserEvaluateChunk { ...@@ -201,6 +201,7 @@ impl EcmascriptBrowserEvaluateChunk {
output_root_to_root_path, output_root_to_root_path,
source_maps, source_maps,
this.chunking_context.chunk_loading_global(), this.chunking_context.chunk_loading_global(),
this.chunking_context.cross_origin(),
esm_chunks, esm_chunks,
); );
code.push_code(&*runtime_code.await?); code.push_code(&*runtime_code.await?);
......
...@@ -5,7 +5,7 @@ use indoc::writedoc; ...@@ -5,7 +5,7 @@ use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::AssetSuffix, chunk::{AssetSuffix, CrossOrigin},
code_builder::{Code, CodeBuilder}, code_builder::{Code, CodeBuilder},
context::AssetContext, context::AssetContext,
environment::ChunkLoading, environment::ChunkLoading,
...@@ -25,6 +25,7 @@ pub async fn get_browser_runtime_code( ...@@ -25,6 +25,7 @@ pub async fn get_browser_runtime_code(
output_root_to_root_path: RcStr, output_root_to_root_path: RcStr,
generate_source_map: bool, generate_source_map: bool,
chunk_loading_global: Vc<RcStr>, chunk_loading_global: Vc<RcStr>,
cross_origin: Vc<CrossOrigin>,
esm_chunks: bool, esm_chunks: bool,
) -> Result<Vc<Code>> { ) -> Result<Vc<Code>> {
let asset_context = *asset_context; let asset_context = *asset_context;
...@@ -96,6 +97,7 @@ pub async fn get_browser_runtime_code( ...@@ -96,6 +97,7 @@ pub async fn get_browser_runtime_code(
let chunk_base_path = chunk_base_path.as_ref().map_or_else(|| "", |f| f.as_str()); let chunk_base_path = chunk_base_path.as_ref().map_or_else(|| "", |f| f.as_str());
let asset_suffix = asset_suffix.await?; let asset_suffix = asset_suffix.await?;
let chunk_loading_global = chunk_loading_global.await?; let chunk_loading_global = chunk_loading_global.await?;
let cross_origin = *cross_origin.await?;
let chunk_lists_global = format!("{}_CHUNK_LISTS", &*chunk_loading_global); let chunk_lists_global = format!("{}_CHUNK_LISTS", &*chunk_loading_global);
if esm_chunks { if esm_chunks {
...@@ -211,6 +213,15 @@ pub async fn get_browser_runtime_code( ...@@ -211,6 +213,15 @@ pub async fn get_browser_runtime_code(
} }
} }
let cross_origin = cross_origin.as_str();
writedoc!(
code,
r#"
var CROSS_ORIGIN = {};
"#,
StringifyJs(&cross_origin)
)?;
// Output the list of global variable names to forward to workers // Output the list of global variable names to forward to workers
let worker_forwarded_globals = worker_forwarded_globals.await?; let worker_forwarded_globals = worker_forwarded_globals.await?;
writedoc!( writedoc!(
......
;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="96069202-5c35-d4fb-392a-fb8a4691db7b")}catch(e){}}(); ;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="694db01f-d95b-4a74-b18c-eadb2804c7ff")}catch(e){}}();
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([ (globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1i9t_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js", "output/1i9t_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js",
{"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvs.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]} {"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvs.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
...@@ -13,6 +13,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../.."; ...@@ -13,6 +13,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = ""; var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : ""; var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : "";
var ASSET_SUFFIX = ""; var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = []; var WORKER_FORWARDED_GLOBALS = [];
/** /**
* This file contains runtime types and functions that are shared between all * This file contains runtime types and functions that are shared between all
...@@ -2083,6 +2084,7 @@ let BACKEND; ...@@ -2083,6 +2084,7 @@ let BACKEND;
} else { } else {
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
link.href = chunkUrl; link.href = chunkUrl;
link.onerror = ()=>{ link.onerror = ()=>{
resolver.reject(); resolver.reject();
...@@ -2107,6 +2109,7 @@ let BACKEND; ...@@ -2107,6 +2109,7 @@ let BACKEND;
} }
} else { } else {
const script = document.createElement('script'); const script = document.createElement('script');
script.crossOrigin = CROSS_ORIGIN;
script.src = chunkUrl; script.src = chunkUrl;
// We'll only mark the chunk as loaded once the script has been executed, // We'll only mark the chunk as loaded once the script has been executed,
// which happens in `registerChunk`. Hence the absence of `resolve()` in // which happens in `registerChunk`. Hence the absence of `resolve()` in
...@@ -2182,6 +2185,7 @@ let DEV_BACKEND; ...@@ -2182,6 +2185,7 @@ let DEV_BACKEND;
} }
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
if (navigator.userAgent.includes('Firefox') || navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') && !navigator.userAgent.includes('Chromium')) { if (navigator.userAgent.includes('Firefox') || navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') && !navigator.userAgent.includes('Chromium')) {
// Firefox won't reload CSS files that were previously loaded on the // Firefox won't reload CSS files that were previously loaded on the
// current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506 // current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506
...@@ -2243,5 +2247,5 @@ chunkListsToRegister.forEach(registerChunkList); ...@@ -2243,5 +2247,5 @@ chunkListsToRegister.forEach(registerChunkList);
})(); })();
//# debugId=96069202-5c35-d4fb-392a-fb8a4691db7b //# debugId=694db01f-d95b-4a74-b18c-eadb2804c7ff
//# sourceMappingURL=1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js.map //# sourceMappingURL=1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js.map
\ No newline at end of file
...@@ -6,6 +6,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../.."; ...@@ -6,6 +6,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = ""; var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = import.meta.url; var RUNTIME_URL = import.meta.url;
var ASSET_SUFFIX = ""; var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = []; var WORKER_FORWARDED_GLOBALS = [];
/** /**
* This file contains runtime types and functions that are shared between all * This file contains runtime types and functions that are shared between all
......
...@@ -12,6 +12,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../.."; ...@@ -12,6 +12,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = ""; var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : ""; var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : "";
var ASSET_SUFFIX = ""; var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = []; var WORKER_FORWARDED_GLOBALS = [];
/** /**
* This file contains runtime types and functions that are shared between all * This file contains runtime types and functions that are shared between all
...@@ -1775,6 +1776,7 @@ var BACKEND; ...@@ -1775,6 +1776,7 @@ var BACKEND;
} else { } else {
var link = document.createElement('link'); var link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
link.href = chunkUrl; link.href = chunkUrl;
link.onerror = function() { link.onerror = function() {
resolver.reject(); resolver.reject();
...@@ -1816,6 +1818,7 @@ var BACKEND; ...@@ -1816,6 +1818,7 @@ var BACKEND;
} }
} else { } else {
var script1 = document.createElement('script'); var script1 = document.createElement('script');
script1.crossOrigin = CROSS_ORIGIN;
script1.src = chunkUrl; script1.src = chunkUrl;
// We'll only mark the chunk as loaded once the script has been executed, // We'll only mark the chunk as loaded once the script has been executed,
// which happens in `registerChunk`. Hence the absence of `resolve()` in // which happens in `registerChunk`. Hence the absence of `resolve()` in
......
...@@ -6,6 +6,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../.."; ...@@ -6,6 +6,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = ""; var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = import.meta.url; var RUNTIME_URL = import.meta.url;
var ASSET_SUFFIX = ""; var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = []; var WORKER_FORWARDED_GLOBALS = [];
/** /**
* This file contains runtime types and functions that are shared between all * This file contains runtime types and functions that are shared between all
...@@ -2160,6 +2161,7 @@ let DEV_BACKEND; ...@@ -2160,6 +2161,7 @@ let DEV_BACKEND;
} }
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
if (navigator.userAgent.includes('Firefox') || navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') && !navigator.userAgent.includes('Chromium')) { if (navigator.userAgent.includes('Firefox') || navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') && !navigator.userAgent.includes('Chromium')) {
// Firefox won't reload CSS files that were previously loaded on the // Firefox won't reload CSS files that were previously loaded on the
// current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506 // current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506
......
...@@ -12,6 +12,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../.."; ...@@ -12,6 +12,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = ""; var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : ""; var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : "";
var ASSET_SUFFIX = ""; var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = []; var WORKER_FORWARDED_GLOBALS = [];
/** /**
* This file contains runtime types and functions that are shared between all * This file contains runtime types and functions that are shared between all
...@@ -2082,6 +2083,7 @@ let BACKEND; ...@@ -2082,6 +2083,7 @@ let BACKEND;
} else { } else {
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
link.href = chunkUrl; link.href = chunkUrl;
link.onerror = ()=>{ link.onerror = ()=>{
resolver.reject(); resolver.reject();
...@@ -2106,6 +2108,7 @@ let BACKEND; ...@@ -2106,6 +2108,7 @@ let BACKEND;
} }
} else { } else {
const script = document.createElement('script'); const script = document.createElement('script');
script.crossOrigin = CROSS_ORIGIN;
script.src = chunkUrl; script.src = chunkUrl;
// We'll only mark the chunk as loaded once the script has been executed, // We'll only mark the chunk as loaded once the script has been executed,
// which happens in `registerChunk`. Hence the absence of `resolve()` in // which happens in `registerChunk`. Hence the absence of `resolve()` in
...@@ -2181,6 +2184,7 @@ let DEV_BACKEND; ...@@ -2181,6 +2184,7 @@ let DEV_BACKEND;
} }
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'stylesheet'; link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
if (navigator.userAgent.includes('Firefox') || navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') && !navigator.userAgent.includes('Chromium')) { if (navigator.userAgent.includes('Firefox') || navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') && !navigator.userAgent.includes('Chromium')) {
// Firefox won't reload CSS files that were previously loaded on the // Firefox won't reload CSS files that were previously loaded on the
// current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506 // current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506
......
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