Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't infinitely set the src which triggers the mutation observe… #287

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/utils/patchUrlMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,20 @@ function recursivelyRemapChildNodes(node: Node, mappings: Mapping[]) {

function attemptSetNodeSrc(node: Node, mappings: Mapping[]) {
if (node instanceof HTMLElement && node.hasAttribute('src')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey

const url = absoluteURL(node.getAttribute('src') ?? '');
const rawSrc = node.getAttribute('src');
const url = absoluteURL(rawSrc ?? '');
if (url.host === window.location.host) return;

if (node.tagName.toLowerCase() === 'script') {
// Scripts are a special case, and need to be wholly recreated since
// modifying a script tag doesn't refetch.
attemptRecreateScriptNode(node, {url, mappings});
} else {
node.setAttribute('src', attemptRemap({url, mappings}).toString());
const newSrc = attemptRemap({url, mappings}).toString();
// Only apply the remapping if we actually remapped the value
if (newSrc !== rawSrc) {
node.setAttribute('src', newSrc);
}
}
}
}
Expand Down
Loading