Skip to content

Commit

Permalink
fix previous firefox double exec fix fml
Browse files Browse the repository at this point in the history
  • Loading branch information
1cg committed Mar 15, 2024
1 parent ea3beb6 commit f353023
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
11 changes: 6 additions & 5 deletions dist/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,23 @@ return (function () {
var fragment = parseHTML("<body><template>" + content + "</template></body>", 0);
// @ts-ignore type mismatch between DocumentFragment and Element.
// TODO: Are these close enough for htmx to use interchangeably?
var fragmentContent = fragment.querySelector('template').content;
if (htmx.config.allowScriptTags) {
// if there is a nonce set up, set it on the new script tags
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
if (htmx.config.inlineScriptNonce) {
script.nonce = htmx.config.inlineScriptNonce;
}
// mark as executed due to template insertion semantics on all browsers except firefox fml
getInternalData(script).executed = navigator.userAgent.indexOf("Firefox") === -1;
script.htmxExecuted = navigator.userAgent.indexOf("Firefox") === -1;
})
} else {
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
// remove all script tags if scripts are disabled
removeElement(script);
})
}
return fragment.querySelector('template').content;
return fragmentContent;
}
switch (startTag) {
case "thead":
Expand Down Expand Up @@ -1907,7 +1908,7 @@ return (function () {
}

function evalScript(script) {
if (!getInternalData(script).executed && htmx.config.allowScriptTags &&
if (!script.htmxExecuted && htmx.config.allowScriptTags &&
(script.type === "text/javascript" || script.type === "module" || script.type === "") ) {
var newScript = getDocument().createElement("script");
forEach(script.attributes, function (attr) {
Expand Down
2 changes: 1 addition & 1 deletion dist/htmx.min.js

Large diffs are not rendered by default.

Binary file modified dist/htmx.min.js.gz
Binary file not shown.
11 changes: 6 additions & 5 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,23 @@ return (function () {
var fragment = parseHTML("<body><template>" + content + "</template></body>", 0);
// @ts-ignore type mismatch between DocumentFragment and Element.
// TODO: Are these close enough for htmx to use interchangeably?
var fragmentContent = fragment.querySelector('template').content;
if (htmx.config.allowScriptTags) {
// if there is a nonce set up, set it on the new script tags
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
if (htmx.config.inlineScriptNonce) {
script.nonce = htmx.config.inlineScriptNonce;
}
// mark as executed due to template insertion semantics on all browsers except firefox fml
getInternalData(script).executed = navigator.userAgent.indexOf("Firefox") === -1;
script.htmxExecuted = navigator.userAgent.indexOf("Firefox") === -1;
})
} else {
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
// remove all script tags if scripts are disabled
removeElement(script);
})
}
return fragment.querySelector('template').content;
return fragmentContent;
}
switch (startTag) {
case "thead":
Expand Down Expand Up @@ -1907,7 +1908,7 @@ return (function () {
}

function evalScript(script) {
if (!getInternalData(script).executed && htmx.config.allowScriptTags &&
if (!script.htmxExecuted && htmx.config.allowScriptTags &&
(script.type === "text/javascript" || script.type === "module" || script.type === "") ) {
var newScript = getDocument().createElement("script");
forEach(script.attributes, function (attr) {
Expand Down
11 changes: 6 additions & 5 deletions www/static/src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,23 @@ return (function () {
var fragment = parseHTML("<body><template>" + content + "</template></body>", 0);
// @ts-ignore type mismatch between DocumentFragment and Element.
// TODO: Are these close enough for htmx to use interchangeably?
var fragmentContent = fragment.querySelector('template').content;
if (htmx.config.allowScriptTags) {
// if there is a nonce set up, set it on the new script tags
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
if (htmx.config.inlineScriptNonce) {
script.nonce = htmx.config.inlineScriptNonce;
}
// mark as executed due to template insertion semantics on all browsers except firefox fml
getInternalData(script).executed = navigator.userAgent.indexOf("Firefox") === -1;
script.htmxExecuted = navigator.userAgent.indexOf("Firefox") === -1;
})
} else {
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
// remove all script tags if scripts are disabled
removeElement(script);
})
}
return fragment.querySelector('template').content;
return fragmentContent;
}
switch (startTag) {
case "thead":
Expand Down Expand Up @@ -1907,7 +1908,7 @@ return (function () {
}

function evalScript(script) {
if (!getInternalData(script).executed && htmx.config.allowScriptTags &&
if (!script.htmxExecuted && htmx.config.allowScriptTags &&
(script.type === "text/javascript" || script.type === "module" || script.type === "") ) {
var newScript = getDocument().createElement("script");
forEach(script.attributes, function (attr) {
Expand Down
11 changes: 6 additions & 5 deletions www/themes/htmx-theme/static/js/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,23 @@ return (function () {
var fragment = parseHTML("<body><template>" + content + "</template></body>", 0);
// @ts-ignore type mismatch between DocumentFragment and Element.
// TODO: Are these close enough for htmx to use interchangeably?
var fragmentContent = fragment.querySelector('template').content;
if (htmx.config.allowScriptTags) {
// if there is a nonce set up, set it on the new script tags
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
if (htmx.config.inlineScriptNonce) {
script.nonce = htmx.config.inlineScriptNonce;
}
// mark as executed due to template insertion semantics on all browsers except firefox fml
getInternalData(script).executed = navigator.userAgent.indexOf("Firefox") === -1;
script.htmxExecuted = navigator.userAgent.indexOf("Firefox") === -1;
})
} else {
forEach(fragment.querySelectorAll("script"), function (script) {
forEach(fragmentContent.querySelectorAll("script"), function (script) {
// remove all script tags if scripts are disabled
removeElement(script);
})
}
return fragment.querySelector('template').content;
return fragmentContent;
}
switch (startTag) {
case "thead":
Expand Down Expand Up @@ -1907,7 +1908,7 @@ return (function () {
}

function evalScript(script) {
if (!getInternalData(script).executed && htmx.config.allowScriptTags &&
if (!script.htmxExecuted && htmx.config.allowScriptTags &&
(script.type === "text/javascript" || script.type === "module" || script.type === "") ) {
var newScript = getDocument().createElement("script");
forEach(script.attributes, function (attr) {
Expand Down

0 comments on commit f353023

Please sign in to comment.