Repository: withastro/astro
File: packages/astro/src/transitions/router.ts (TypeScript)

Code before:
		// can't fetch, let someone else deal with it.
		return null;
	}
}

export function getFallback(): Fallback {
	const el = document.querySelector('[name="astro-view-transitions-fallback"]');
	if (el) {
		return el.getAttribute('content') as Fallback;
	}
	return 'animate';
}

const scriptsAlreadyRan = new Set<string>();
const detectScriptExecuted = (script: HTMLScriptElement) => {
	const key = script.src ? new URL(script.src, location.href).href : script.textContent!;
	if (scriptsAlreadyRan.has(key)) return true;
	scriptsAlreadyRan.add(key);
	return false;
};
function runScripts() {
	let wait = Promise.resolve();
	for (const script of document.getElementsByTagName('script')) {
		if (detectScriptExecuted(script)) continue;
		const type = script.getAttribute('type');
		if (type && type !== 'module' && type !== 'text/javascript') continue;
		const newScript = document.createElement('script');
		newScript.innerHTML = script.innerHTML;
		for (const attr of script.attributes) {
			if (attr.name === 'src') {
				const p = new Promise((r) => {
					newScript.onload = newScript.onerror = r;
				});
				wait = wait.then(() => p as any);
			}
			newScript.setAttribute(attr.name, attr.value);
		}
		script.replaceWith(newScript);
	}
	return wait;
}

// Add a new entry to the browser history. This also sets the new page in the browser address bar.
// Sets the scroll position according to the hash fragment of the new location.
const moveToLocation = (
	to: URL,
	from: URL,
	options: Options,
	pageTitleForBrowserHistory: string,
	historyState?: State,
) => {

Review comment (suggestion):
maybe move checking the type attribute two lines up as we do not need to remember e.g. speculation rules, import maps, or partytown scripts 

Code after:
	} catch {
		// can't fetch, let someone else deal with it.
		return null;
	}
}

export function getFallback(): Fallback {
	const el = document.querySelector('[name="astro-view-transitions-fallback"]');
	if (el) {
		return el.getAttribute('content') as Fallback;
	}
	return 'animate';
}

function runScripts() {
	let wait = Promise.resolve();
	for (const script of document.getElementsByTagName('script')) {
		if (script.dataset.astroExec === '') continue;
		const type = script.getAttribute('type');
		if (type && type !== 'module' && type !== 'text/javascript') continue;
		const newScript = document.createElement('script');
		newScript.innerHTML = script.innerHTML;
		for (const attr of script.attributes) {
			if (attr.name === 'src') {
				const p = new Promise((r) => {
					newScript.onload = newScript.onerror = r;
				});
				wait = wait.then(() => p as any);
			}
			newScript.setAttribute(attr.name, attr.value);
		}
		newScript.dataset.astroExec = '';
		script.replaceWith(newScript);
	}
	return wait;
}

// Add a new entry to the browser history. This also sets the new page in the browser address bar.
// Sets the scroll position according to the hash fragment of the new location.
const moveToLocation = (
	to: URL,
	from: URL,
	options: Options,
	pageTitleForBrowserHistory: string,
	historyState?: State,
) => {
	const intraPage = samePage(from, to);

	const targetPageTitle = document.title;
	document.title = pageTitleForBrowserHistory;