Skip to content

Commit 42fe8e0

Browse files
author
Rishi Raj Jain
authored
fix: Script with innerHTML not working on Safari (#4861)
* fix: Script with innerHTML not working on Safari * Update cool-camels-tease.md
1 parent 83ed1cc commit 42fe8e0

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.changeset/cool-camels-tease.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
use const instead of let for define:vars

packages/astro/src/runtime/server/render/util.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const toStyleString = (obj: Record<string, any>) =>
3434
export function defineScriptVars(vars: Record<any, any>) {
3535
let output = '';
3636
for (const [key, value] of Object.entries(vars)) {
37-
output += `let ${toIdent(key)} = ${JSON.stringify(value)};\n`;
37+
// Use const instead of let as let global unsupported with Safari
38+
// https://stackoverflow.com/questions/29194024/cant-use-let-keyword-in-safari-javascript
39+
output += `const ${toIdent(key)} = ${JSON.stringify(value)};\n`;
3840
}
3941
return markHTMLString(output);
4042
}

packages/astro/test/astro-directives.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ describe('Directives', async () => {
2323
expect($(script).text().at(-1)).to.equal('}');
2424
if (i < 2) {
2525
// Inline defined variables
26-
expect($(script).toString()).to.include('let foo = "bar"');
26+
expect($(script).toString()).to.include('const foo = "bar"');
2727
} else {
2828
// Convert invalid keys to valid identifiers
29-
expect($(script).toString()).to.include('let dashCase = "bar"');
29+
expect($(script).toString()).to.include('const dashCase = "bar"');
3030
}
3131
i++;
3232
}

0 commit comments

Comments
 (0)