Skip to content

Commit

Permalink
Fix define:vars in the static build flag (withastro#2511)
Browse files Browse the repository at this point in the history
* Fix define:vars in the static build flag

* Adds a changeset

* linting
  • Loading branch information
matthewp committed Jan 31, 2022
1 parent 187d512 commit 3d2c184
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-lamps-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Bug fix for define:vars with the --experimental-static-build flag
13 changes: 13 additions & 0 deletions examples/fast-build/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import ExternalHoisted from '../components/ExternalHoisted.astro';
color: purple;
}
</style>
<style define:vars={{ color: 'blue' }}>
.define-vars h1 {
color: var(--color);
}
</style>
</head>
<body>
<section>
Expand Down Expand Up @@ -58,5 +63,13 @@ import ExternalHoisted from '../components/ExternalHoisted.astro';
<InlineHoisted />
<ExternalHoisted />
</section>

<section class="define-vars">
<h1>define:vars</h1>
<h2></h2>
<script define:vars={{ color: 'blue' }}>
document.querySelector('.define-vars h2').textContent = `Color: ${color}`;
</script>
</section>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"test:match": "mocha --timeout 15000 -g"
},
"dependencies": {
"@astrojs/compiler": "^0.9.2",
"@astrojs/compiler": "^0.10.0",
"@astrojs/language-server": "^0.8.6",
"@astrojs/markdown-remark": "^0.6.0",
"@astrojs/prism": "0.4.0",
Expand Down
20 changes: 10 additions & 10 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,16 @@ const uniqueElements = (item: any, index: number, all: any[]) => {
// styles and scripts into the head.
export async function renderPage(result: SSRResult, Component: AstroComponentFactory, props: any, children: any) {
const template = await renderToString(result, Component, props, children);
const styles = result._metadata.experimentalStaticBuild
? []
: Array.from(result.styles)
.filter(uniqueElements)
.map((style) =>
renderElement('style', {
...style,
props: { ...style.props, 'astro-style': true },
})
);
const styles = Array.from(result.styles)
.filter(uniqueElements)
.map((style) => {
const styleChildren = result._metadata.experimentalStaticBuild ? '' : style.children;

return renderElement('style', {
children: styleChildren,
props: { ...style.props, 'astro-style': true },
});
});
let needsHydrationStyles = false;
const scripts = Array.from(result.scripts)
.filter(uniqueElements)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@
jsonpointer "^5.0.0"
leven "^3.1.0"

"@astrojs/compiler@^0.9.2":
version "0.9.2"
resolved "https://registry.yarnpkg.com/@astrojs/compiler/-/compiler-0.9.2.tgz#aea226472046cb88c0ff20661be34af84d983feb"
integrity sha512-8yxdyokSNmTbcDfW75k5NcPKMBnPTfzLHVxhdiUrII7Zqh/OG9SaOZWFCnvFhU8dkQBUU6B1eh/ABAHwnxZWGw==
"@astrojs/compiler@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@astrojs/compiler/-/compiler-0.10.0.tgz#6ba2707bf9a91017fd72fb46b1d7865036b71c09"
integrity sha512-TbeuITyhRGlQowipNX7Q8o5QczVjSxlE68xKh7i1swTxUhM8K/cnCPSyzTsWiuFWY4C5PDI1GREUaD3BHYfzqQ==
dependencies:
typescript "^4.3.5"

Expand Down

0 comments on commit 3d2c184

Please sign in to comment.