Skip to content

Commit

Permalink
fix: avoid using variable in template (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Mar 8, 2023
1 parent 4c0621d commit 7808941
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-years-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Avoid using $global in internal templates.
11 changes: 5 additions & 6 deletions src/components/vite.marko
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ static function renderAssets(slot) {
return html;
}
$ const $global = out.global;
$ if (!$global.___viteRenderAssets) {
$global.___viteInjectAttrs = $global.cspNonce
? ` nonce="${$global.cspNonce.replace(/"/g, "'")}"`
$ if (!out.global.___viteRenderAssets) {
out.global.___viteInjectAttrs = out.global.cspNonce
? ` nonce="${out.global.cspNonce.replace(/"/g, "'")}"`
: "";
$global.___viteRenderAssets = renderAssets;
out.global.___viteRenderAssets = renderAssets;
}
<__flush_here_and_after__>
$!{$global.___viteRenderAssets(input.slot)}
$!{out.global.___viteRenderAssets(input.slot)}
</__flush_here_and_after__>
5 changes: 2 additions & 3 deletions src/server-entry-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ export default async (opts: {
const fileNameStr = JSON.stringify(`./${path.basename(opts.fileName)}`);
return `import template from ${fileNameStr};
export * from ${fileNameStr};
$ const $global = out.global;
${
opts.runtimeId
? `$ $global.runtimeId = ${JSON.stringify(opts.runtimeId)};\n`
? `$ out.global.runtimeId = ${JSON.stringify(opts.runtimeId)};\n`
: ""
}$ ($global.___viteEntries || ($global.___viteEntries = [])).push(${
}$ (out.global.___viteEntries || (out.global.___viteEntries = [])).push(${
opts.entryData
});
<_vite slot="head-prepend"/>
Expand Down

0 comments on commit 7808941

Please sign in to comment.