fix: Script with innerHTML not working on Safari (#4861)
* fix: Script with innerHTML not working on Safari * Update cool-camels-tease.md
This commit is contained in:
parent
83ed1cc1f2
commit
42fe8e0c7f
3 changed files with 10 additions and 3 deletions
5
.changeset/cool-camels-tease.md
Normal file
5
.changeset/cool-camels-tease.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
use const instead of let for define:vars
|
|
@ -34,7 +34,9 @@ const toStyleString = (obj: Record<string, any>) =>
|
||||||
export function defineScriptVars(vars: Record<any, any>) {
|
export function defineScriptVars(vars: Record<any, any>) {
|
||||||
let output = '';
|
let output = '';
|
||||||
for (const [key, value] of Object.entries(vars)) {
|
for (const [key, value] of Object.entries(vars)) {
|
||||||
output += `let ${toIdent(key)} = ${JSON.stringify(value)};\n`;
|
// Use const instead of let as let global unsupported with Safari
|
||||||
|
// https://stackoverflow.com/questions/29194024/cant-use-let-keyword-in-safari-javascript
|
||||||
|
output += `const ${toIdent(key)} = ${JSON.stringify(value)};\n`;
|
||||||
}
|
}
|
||||||
return markHTMLString(output);
|
return markHTMLString(output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ describe('Directives', async () => {
|
||||||
expect($(script).text().at(-1)).to.equal('}');
|
expect($(script).text().at(-1)).to.equal('}');
|
||||||
if (i < 2) {
|
if (i < 2) {
|
||||||
// Inline defined variables
|
// Inline defined variables
|
||||||
expect($(script).toString()).to.include('let foo = "bar"');
|
expect($(script).toString()).to.include('const foo = "bar"');
|
||||||
} else {
|
} else {
|
||||||
// Convert invalid keys to valid identifiers
|
// Convert invalid keys to valid identifiers
|
||||||
expect($(script).toString()).to.include('let dashCase = "bar"');
|
expect($(script).toString()).to.include('const dashCase = "bar"');
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue