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::{
asset::{Asset, AssetContent},
chunk::{
AssetSuffix, Chunk, ChunkGroupResult, ChunkItem, ChunkType, ChunkableModule,
ChunkingConfig, ChunkingConfigs, ChunkingContext, ContentHashing, EntryChunkGroupResult,
EvaluatableAsset, EvaluatableAssets, MinifyType, SourceMapSourceType, SourceMapsType,
UnusedReferences, UrlBehavior,
ChunkingConfig, ChunkingConfigs, ChunkingContext, ContentHashing, CrossOrigin,
EntryChunkGroupResult, EvaluatableAsset, EvaluatableAssets, MinifyType,
SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
availability_info::AvailabilityInfo,
chunk_group::{MakeChunkGroupResult, make_chunk_group},
chunk_id_strategy::ModuleIdStrategy,
......@@ -224,6 +224,11 @@ impl BrowserChunkingContextBuilder {
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 {
self.chunking_context.esm_chunks = esm_chunks;
self
......@@ -327,6 +332,8 @@ pub struct BrowserChunkingContext {
chunk_loading_global: Option<RcStr>,
/// Salt mixed into chunk and asset content hashes. Empty string means no salt.
hash_salt: ResolvedVc<RcStr>,
/// The crossorigin mode for dynamically loaded chunks.
cross_origin: CrossOrigin,
/// Emit chunks as ES modules (`export default [factories...]`) instead of
/// `globalThis["TURBOPACK"].push([...])`. The runtime loads them via `import()`.
/// Requires `current_chunk_method` to be set to `ImportMetaUrl` when used.
......@@ -384,6 +391,7 @@ impl BrowserChunkingContext {
worker_forwarded_globals: vec![],
chunk_loading_global: Default::default(),
hash_salt: ResolvedVc::cell(RcStr::default()),
cross_origin: Default::default(),
esm_chunks: false,
},
}
......@@ -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.
#[turbo_tasks::function]
pub fn esm_chunks(&self) -> Vc<bool> {
......
......@@ -201,6 +201,7 @@ impl EcmascriptBrowserEvaluateChunk {
output_root_to_root_path,
source_maps,
this.chunking_context.chunk_loading_global(),
this.chunking_context.cross_origin(),
esm_chunks,
);
code.push_code(&*runtime_code.await?);
......
......@@ -5,7 +5,7 @@ use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{
chunk::AssetSuffix,
chunk::{AssetSuffix, CrossOrigin},
code_builder::{Code, CodeBuilder},
context::AssetContext,
environment::ChunkLoading,
......@@ -25,6 +25,7 @@ pub async fn get_browser_runtime_code(
output_root_to_root_path: RcStr,
generate_source_map: bool,
chunk_loading_global: Vc<RcStr>,
cross_origin: Vc<CrossOrigin>,
esm_chunks: bool,
) -> Result<Vc<Code>> {
let asset_context = *asset_context;
......@@ -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 asset_suffix = asset_suffix.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);
if esm_chunks {
......@@ -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
let worker_forwarded_globals = worker_forwarded_globals.await?;
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([
"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)"]}
......@@ -13,6 +13,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : "";
var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = [];
/**
* This file contains runtime types and functions that are shared between all
......@@ -2083,6 +2084,7 @@ let BACKEND;
} else {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
link.href = chunkUrl;
link.onerror = ()=>{
resolver.reject();
......@@ -2107,6 +2109,7 @@ let BACKEND;
}
} else {
const script = document.createElement('script');
script.crossOrigin = CROSS_ORIGIN;
script.src = chunkUrl;
// We'll only mark the chunk as loaded once the script has been executed,
// which happens in `registerChunk`. Hence the absence of `resolve()` in
......@@ -2182,6 +2185,7 @@ let DEV_BACKEND;
}
const link = document.createElement('link');
link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
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
// current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506
......@@ -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
\ No newline at end of file
......@@ -6,6 +6,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = import.meta.url;
var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = [];
/**
* This file contains runtime types and functions that are shared between all
......
......@@ -12,6 +12,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : "";
var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = [];
/**
* This file contains runtime types and functions that are shared between all
......@@ -1775,6 +1776,7 @@ var BACKEND;
} else {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
link.href = chunkUrl;
link.onerror = function() {
resolver.reject();
......@@ -1816,6 +1818,7 @@ var BACKEND;
}
} else {
var script1 = document.createElement('script');
script1.crossOrigin = CROSS_ORIGIN;
script1.src = chunkUrl;
// We'll only mark the chunk as loaded once the script has been executed,
// which happens in `registerChunk`. Hence the absence of `resolve()` in
......
......@@ -6,6 +6,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = import.meta.url;
var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = [];
/**
* This file contains runtime types and functions that are shared between all
......@@ -2160,6 +2161,7 @@ let DEV_BACKEND;
}
const link = document.createElement('link');
link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
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
// current page: https://bugzilla.mozilla.org/show_bug.cgi?id=1037506
......
......@@ -12,6 +12,7 @@ var RELATIVE_ROOT_PATH = "../../../../../../..";
var RUNTIME_PUBLIC_PATH = "";
var RUNTIME_URL = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : "";
var ASSET_SUFFIX = "";
var CROSS_ORIGIN = null;
var WORKER_FORWARDED_GLOBALS = [];
/**
* This file contains runtime types and functions that are shared between all
......@@ -2082,6 +2083,7 @@ let BACKEND;
} else {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
link.href = chunkUrl;
link.onerror = ()=>{
resolver.reject();
......@@ -2106,6 +2108,7 @@ let BACKEND;
}
} else {
const script = document.createElement('script');
script.crossOrigin = CROSS_ORIGIN;
script.src = chunkUrl;
// We'll only mark the chunk as loaded once the script has been executed,
// which happens in `registerChunk`. Hence the absence of `resolve()` in
......@@ -2181,6 +2184,7 @@ let DEV_BACKEND;
}
const link = document.createElement('link');
link.rel = 'stylesheet';
link.crossOrigin = CROSS_ORIGIN;
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
// 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