Unverified Commit 10a3c968 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

fix(turbopack): preserve external script lookup after canary rebase

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent af5d9829
...@@ -97,6 +97,8 @@ describeTurbopack('turbopack module federation with a webpack remote', () => { ...@@ -97,6 +97,8 @@ describeTurbopack('turbopack module federation with a webpack remote', () => {
afterAll(async () => { afterAll(async () => {
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
remoteServer.close((error) => (error ? reject(error) : resolve())) remoteServer.close((error) => (error ? reject(error) : resolve()))
// Browser connections can remain open until the Next.js fixture is destroyed.
remoteServer.closeAllConnections()
}) })
delete process.env.MF_REMOTE_ORIGIN delete process.env.MF_REMOTE_ORIGIN
delete process.env.NEXT_PUBLIC_MF_REMOTE_ORIGIN delete process.env.NEXT_PUBLIC_MF_REMOTE_ORIGIN
......
...@@ -55,15 +55,26 @@ function matchesChunkUrl( ...@@ -55,15 +55,26 @@ function matchesChunkUrl(
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
* External scripts also match equivalent absolute and relative URLs.
*/ */
function findChunkScripts(url: string): HTMLScriptElement[] { function findChunkScripts(
url: string,
external: boolean = false
): HTMLScriptElement[] {
const decodedUrl = decodeURI(url) const decodedUrl = decodeURI(url)
const requested = external ? new URL(url, document.baseURI).href : undefined
const scripts = document.head.getElementsByTagName('script') const scripts = document.head.getElementsByTagName('script')
const result: HTMLScriptElement[] = [] const result: HTMLScriptElement[] = []
for (let i = 0; i < scripts.length; i++) { for (let i = 0; i < scripts.length; i++) {
const script = scripts[i] const script = scripts[i]
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { const src = script.getAttribute('src')
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script) result.push(script)
} else if (requested !== undefined && src !== null) {
const existing = new URL(src, document.baseURI).href
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script)
}
} }
} }
return result return result
...@@ -376,7 +387,7 @@ const chunkResolvers: Map<ChunkUrl, ChunkResolver> = new Map() ...@@ -376,7 +387,7 @@ const chunkResolvers: Map<ChunkUrl, ChunkResolver> = new Map()
document.head.appendChild(createLink()) document.head.appendChild(createLink())
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
const previousScripts = findChunkScripts(chunkUrl) const previousScripts = findChunkScripts(chunkUrl, resolveOnLoad)
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
for (const script of previousScripts) { for (const script of previousScripts) {
script.addEventListener('load', () => markChunkLoaded(resolver), { script.addEventListener('load', () => markChunkLoaded(resolver), {
......
;!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]="5885813e-75c7-97e6-7e72-9587bc5ac6b6")}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]="26c61e4a-7df9-d221-5e92-7bc327f7a2b5")}catch(e){}}();
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([ (globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/0rv8_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js", "output/0rv8_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js",
{"otherChunks":["output/0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvsq4xsbk.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]} {"otherChunks":["output/0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvsq4xsbk.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
...@@ -2316,14 +2316,22 @@ function getAssetSuffixFromScriptSrc() { ...@@ -2316,14 +2316,22 @@ function getAssetSuffixFromScriptSrc() {
// CSS-escaped. // CSS-escaped.
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
*/ function findChunkScripts(url) { * External scripts also match equivalent absolute and relative URLs.
*/ function findChunkScripts(url, external = false) {
const decodedUrl = decodeURI(url); const decodedUrl = decodeURI(url);
const requested = external ? new URL(url, document.baseURI).href : undefined;
const scripts = document.head.getElementsByTagName('script'); const scripts = document.head.getElementsByTagName('script');
const result = []; const result = [];
for(let i = 0; i < scripts.length; i++){ for(let i = 0; i < scripts.length; i++){
const script = scripts[i]; const script = scripts[i];
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { const src = script.getAttribute('src');
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script); result.push(script);
} else if (requested !== undefined && src !== null) {
const existing = new URL(src, document.baseURI).href;
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script);
}
} }
} }
return result; return result;
...@@ -2536,7 +2544,7 @@ let BACKEND; ...@@ -2536,7 +2544,7 @@ let BACKEND;
document.head.appendChild(createLink()); document.head.appendChild(createLink());
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
const previousScripts = findChunkScripts(chunkUrl); const previousScripts = findChunkScripts(chunkUrl, resolveOnLoad);
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
for (const script of previousScripts){ for (const script of previousScripts){
script.addEventListener('load', ()=>markChunkLoaded(resolver), { script.addEventListener('load', ()=>markChunkLoaded(resolver), {
...@@ -2689,5 +2697,5 @@ chunkListsToRegister.forEach(registerChunkList); ...@@ -2689,5 +2697,5 @@ chunkListsToRegister.forEach(registerChunkList);
})(); })();
//# debugId=5885813e-75c7-97e6-7e72-9587bc5ac6b6 //# debugId=26c61e4a-7df9-d221-5e92-7bc327f7a2b5
//# sourceMappingURL=0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js.map //# sourceMappingURL=0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js.map
\ No newline at end of file
...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() { ...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() {
// CSS-escaped. // CSS-escaped.
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
*/ function findChunkScripts(url) { * External scripts also match equivalent absolute and relative URLs.
*/ function findChunkScripts(url, external = false) {
const decodedUrl = decodeURI(url); const decodedUrl = decodeURI(url);
const requested = external ? new URL(url, document.baseURI).href : undefined;
const scripts = document.head.getElementsByTagName('script'); const scripts = document.head.getElementsByTagName('script');
const result = []; const result = [];
for(let i = 0; i < scripts.length; i++){ for(let i = 0; i < scripts.length; i++){
const script = scripts[i]; const script = scripts[i];
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { const src = script.getAttribute('src');
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script); result.push(script);
} else if (requested !== undefined && src !== null) {
const existing = new URL(src, document.baseURI).href;
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script);
}
} }
} }
return result; return result;
...@@ -2535,7 +2543,7 @@ let BACKEND; ...@@ -2535,7 +2543,7 @@ let BACKEND;
document.head.appendChild(createLink()); document.head.appendChild(createLink());
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
const previousScripts = findChunkScripts(chunkUrl); const previousScripts = findChunkScripts(chunkUrl, resolveOnLoad);
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
for (const script of previousScripts){ for (const script of previousScripts){
script.addEventListener('load', ()=>markChunkLoaded(resolver), { script.addEventListener('load', ()=>markChunkLoaded(resolver), {
......
...@@ -1799,14 +1799,23 @@ function getAssetSuffixFromScriptSrc() { ...@@ -1799,14 +1799,23 @@ function getAssetSuffixFromScriptSrc() {
// CSS-escaped. // CSS-escaped.
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
* External scripts also match equivalent absolute and relative URLs.
*/ function findChunkScripts(url) { */ function findChunkScripts(url) {
var external = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
var decodedUrl = decodeURI(url); var decodedUrl = decodeURI(url);
var requested = external ? new URL(url, document.baseURI).href : undefined;
var scripts = document.head.getElementsByTagName('script'); var scripts = document.head.getElementsByTagName('script');
var result = []; var result = [];
for(var i = 0; i < scripts.length; i++){ for(var i = 0; i < scripts.length; i++){
var script = scripts[i]; var script = scripts[i];
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { var src = script.getAttribute('src');
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script); result.push(script);
} else if (requested !== undefined && src !== null) {
var existing = new URL(src, document.baseURI).href;
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script);
}
} }
} }
return result; return result;
...@@ -2080,7 +2089,7 @@ var BACKEND; ...@@ -2080,7 +2089,7 @@ var BACKEND;
document.head.appendChild(createLink()); document.head.appendChild(createLink());
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
var previousScripts = findChunkScripts(chunkUrl); var previousScripts = findChunkScripts(chunkUrl, resolveOnLoad);
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try { try {
......
...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() { ...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() {
// CSS-escaped. // CSS-escaped.
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
*/ function findChunkScripts(url) { * External scripts also match equivalent absolute and relative URLs.
*/ function findChunkScripts(url, external = false) {
const decodedUrl = decodeURI(url); const decodedUrl = decodeURI(url);
const requested = external ? new URL(url, document.baseURI).href : undefined;
const scripts = document.head.getElementsByTagName('script'); const scripts = document.head.getElementsByTagName('script');
const result = []; const result = [];
for(let i = 0; i < scripts.length; i++){ for(let i = 0; i < scripts.length; i++){
const script = scripts[i]; const script = scripts[i];
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { const src = script.getAttribute('src');
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script); result.push(script);
} else if (requested !== undefined && src !== null) {
const existing = new URL(src, document.baseURI).href;
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script);
}
} }
} }
return result; return result;
...@@ -2535,7 +2543,7 @@ let BACKEND; ...@@ -2535,7 +2543,7 @@ let BACKEND;
document.head.appendChild(createLink()); document.head.appendChild(createLink());
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
const previousScripts = findChunkScripts(chunkUrl); const previousScripts = findChunkScripts(chunkUrl, resolveOnLoad);
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
for (const script of previousScripts){ for (const script of previousScripts){
script.addEventListener('load', ()=>markChunkLoaded(resolver), { script.addEventListener('load', ()=>markChunkLoaded(resolver), {
......
...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() { ...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() {
// CSS-escaped. // CSS-escaped.
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
*/ function findChunkScripts(url) { * External scripts also match equivalent absolute and relative URLs.
*/ function findChunkScripts(url, external = false) {
const decodedUrl = decodeURI(url); const decodedUrl = decodeURI(url);
const requested = external ? new URL(url, document.baseURI).href : undefined;
const scripts = document.head.getElementsByTagName('script'); const scripts = document.head.getElementsByTagName('script');
const result = []; const result = [];
for(let i = 0; i < scripts.length; i++){ for(let i = 0; i < scripts.length; i++){
const script = scripts[i]; const script = scripts[i];
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { const src = script.getAttribute('src');
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script); result.push(script);
} else if (requested !== undefined && src !== null) {
const existing = new URL(src, document.baseURI).href;
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script);
}
} }
} }
return result; return result;
...@@ -2535,7 +2543,7 @@ let BACKEND; ...@@ -2535,7 +2543,7 @@ let BACKEND;
document.head.appendChild(createLink()); document.head.appendChild(createLink());
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
const previousScripts = findChunkScripts(chunkUrl); const previousScripts = findChunkScripts(chunkUrl, resolveOnLoad);
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
for (const script of previousScripts){ for (const script of previousScripts){
script.addEventListener('load', ()=>markChunkLoaded(resolver), { script.addEventListener('load', ()=>markChunkLoaded(resolver), {
......
...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() { ...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() {
// CSS-escaped. // CSS-escaped.
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
*/ function findChunkScripts(url) { * External scripts also match equivalent absolute and relative URLs.
*/ function findChunkScripts(url, external = false) {
const decodedUrl = decodeURI(url); const decodedUrl = decodeURI(url);
const requested = external ? new URL(url, document.baseURI).href : undefined;
const scripts = document.head.getElementsByTagName('script'); const scripts = document.head.getElementsByTagName('script');
const result = []; const result = [];
for(let i = 0; i < scripts.length; i++){ for(let i = 0; i < scripts.length; i++){
const script = scripts[i]; const script = scripts[i];
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { const src = script.getAttribute('src');
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script); result.push(script);
} else if (requested !== undefined && src !== null) {
const existing = new URL(src, document.baseURI).href;
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script);
}
} }
} }
return result; return result;
...@@ -2535,7 +2543,7 @@ let BACKEND; ...@@ -2535,7 +2543,7 @@ let BACKEND;
document.head.appendChild(createLink()); document.head.appendChild(createLink());
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
const previousScripts = findChunkScripts(chunkUrl); const previousScripts = findChunkScripts(chunkUrl, resolveOnLoad);
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
for (const script of previousScripts){ for (const script of previousScripts){
script.addEventListener('load', ()=>markChunkLoaded(resolver), { script.addEventListener('load', ()=>markChunkLoaded(resolver), {
......
...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() { ...@@ -2315,14 +2315,22 @@ function getAssetSuffixFromScriptSrc() {
// CSS-escaped. // CSS-escaped.
/** /**
* Returns all `<script>` elements in `<head>` whose `src` refers to `url`. * Returns all `<script>` elements in `<head>` whose `src` refers to `url`.
*/ function findChunkScripts(url) { * External scripts also match equivalent absolute and relative URLs.
*/ function findChunkScripts(url, external = false) {
const decodedUrl = decodeURI(url); const decodedUrl = decodeURI(url);
const requested = external ? new URL(url, document.baseURI).href : undefined;
const scripts = document.head.getElementsByTagName('script'); const scripts = document.head.getElementsByTagName('script');
const result = []; const result = [];
for(let i = 0; i < scripts.length; i++){ for(let i = 0; i < scripts.length; i++){
const script = scripts[i]; const script = scripts[i];
if (matchesChunkUrl(script.getAttribute('src'), url, decodedUrl)) { const src = script.getAttribute('src');
if (matchesChunkUrl(src, url, decodedUrl)) {
result.push(script); result.push(script);
} else if (requested !== undefined && src !== null) {
const existing = new URL(src, document.baseURI).href;
if (existing === requested || existing.startsWith(`${requested}?`)) {
result.push(script);
}
} }
} }
return result; return result;
...@@ -2535,7 +2543,7 @@ let BACKEND; ...@@ -2535,7 +2543,7 @@ let BACKEND;
document.head.appendChild(createLink()); document.head.appendChild(createLink());
} }
} else if (isJs(chunkUrl)) { } else if (isJs(chunkUrl)) {
const previousScripts = findChunkScripts(chunkUrl); const previousScripts = findChunkScripts(chunkUrl, resolveOnLoad);
if (previousScripts.length > 0) { if (previousScripts.length > 0) {
for (const script of previousScripts){ for (const script of previousScripts){
script.addEventListener('load', ()=>markChunkLoaded(resolver), { script.addEventListener('load', ()=>markChunkLoaded(resolver), {
......
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