Skip to content

Commit 7adc57e

Browse files
authored
fix: don't infinitely set the src which triggers the mutation observer again (#287)
1 parent 9ff4e82 commit 7adc57e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/utils/patchUrlMappings.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,20 @@ function recursivelyRemapChildNodes(node: Node, mappings: Mapping[]) {
127127

128128
function attemptSetNodeSrc(node: Node, mappings: Mapping[]) {
129129
if (node instanceof HTMLElement && node.hasAttribute('src')) {
130-
const url = absoluteURL(node.getAttribute('src') ?? '');
130+
const rawSrc = node.getAttribute('src');
131+
const url = absoluteURL(rawSrc ?? '');
131132
if (url.host === window.location.host) return;
132133

133134
if (node.tagName.toLowerCase() === 'script') {
134135
// Scripts are a special case, and need to be wholly recreated since
135136
// modifying a script tag doesn't refetch.
136137
attemptRecreateScriptNode(node, {url, mappings});
137138
} else {
138-
node.setAttribute('src', attemptRemap({url, mappings}).toString());
139+
const newSrc = attemptRemap({url, mappings}).toString();
140+
// Only apply the remapping if we actually remapped the value
141+
if (newSrc !== rawSrc) {
142+
node.setAttribute('src', newSrc);
143+
}
139144
}
140145
}
141146
}

0 commit comments

Comments
 (0)