Merge branch 'main' into astro-quicklink

This commit is contained in:
Tony Sullivan 2022-06-27 15:08:02 +00:00 committed by GitHub
commit b8210c87ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 111 additions and 131 deletions

View file

@ -9,6 +9,6 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/preact": "^0.2.0",
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"sass": "^1.52.2"
},
"dependencies": {

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/preact": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"preact": "^10.7.3"

View file

@ -10,6 +10,6 @@
},
"devDependencies": {
"@example/my-component": "workspace:*",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -8,6 +8,6 @@
"serve": "astro --root demo preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -20,6 +20,6 @@
"devDependencies": {
"@astrojs/preact": "^0.2.0",
"@astrojs/react": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -9,6 +9,6 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -9,7 +9,7 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"alpinejs": "^3.10.2"

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/lit": "^0.3.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"@webcomponents/template-shadowroot": "^0.1.0",

View file

@ -15,7 +15,7 @@
"@astrojs/solid-js": "^0.2.0",
"@astrojs/svelte": "^0.2.0",
"@astrojs/vue": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"@webcomponents/template-shadowroot": "^0.1.0",

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/preact": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"preact": "^10.7.3"

View file

@ -12,7 +12,7 @@
"@astrojs/react": "^0.2.0",
"@types/react": "^18.0.10",
"@types/react-dom": "^18.0.5",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"react": "^18.1.0",

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/solid-js": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"solid-js": "^1.4.3"

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/svelte": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"svelte": "^3.48.0"

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/vue": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"vue": "^3.2.36"

View file

@ -16,7 +16,7 @@
"@astrojs/solid-js": "0.2.0",
"@astrojs/tailwind": "^0.2.1",
"@astrojs/turbolinks": "^0.1.3",
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"solid-js": "^1.4.3"
},
"dependencies": {

View file

@ -9,6 +9,6 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -9,6 +9,6 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/preact": "^0.2.0",
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"sass": "^1.52.2"
},
"dependencies": {

View file

@ -11,7 +11,7 @@
"devDependencies": {
"@astrojs/node": "^0.1.2",
"@astrojs/svelte": "^0.2.0",
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"concurrently": "^7.2.1",
"lightcookie": "^1.0.25",
"unocss": "^0.15.6",

View file

@ -9,6 +9,6 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/react": "^0.2.0",
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"sass": "^1.52.2"
},
"dependencies": {

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/markdown-remark": "^0.11.3",
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"hast-util-select": "5.0.1",
"rehype-autolink-headings": "^6.1.1",
"rehype-slug": "^5.0.1",

View file

@ -10,6 +10,6 @@
},
"devDependencies": {
"@astrojs/markdown-remark": "^0.11.3",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -14,7 +14,7 @@
"@astrojs/react": "^0.2.0",
"@astrojs/svelte": "^0.2.0",
"@astrojs/vue": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
},
"dependencies": {
"preact": "^10.7.3",

View file

@ -25,6 +25,6 @@
"@astrojs/solid-js": "^0.2.0",
"@astrojs/svelte": "^0.2.0",
"@astrojs/vue": "^0.2.0",
"astro": "^1.0.0-beta.56"
"astro": "^1.0.0-beta.57"
}
}

View file

@ -10,7 +10,7 @@
},
"devDependencies": {
"@astrojs/tailwind": "^0.2.1",
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"autoprefixer": "^10.4.7",
"canvas-confetti": "^1.5.1",
"postcss": "^8.4.14",

View file

@ -9,7 +9,7 @@
"preview": "astro preview"
},
"devDependencies": {
"astro": "^1.0.0-beta.56",
"astro": "^1.0.0-beta.57",
"vite-plugin-pwa": "0.11.11",
"workbox-window": "^6.5.3"
}

View file

@ -1,5 +1,11 @@
# astro
## 1.0.0-beta.57
### Patch Changes
- [#3724](https://github.com/withastro/astro/pull/3724) [`86635e03`](https://github.com/withastro/astro/commit/86635e035b209845b4e1cdf370a4c78451271b70) Thanks [@matthewp](https://github.com/matthewp)! - Fixes define:vars w/ styles used inside of components
## 1.0.0-beta.56
### Patch Changes

View file

@ -1,6 +1,6 @@
{
"name": "astro",
"version": "1.0.0-beta.56",
"version": "1.0.0-beta.57",
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
"type": "module",
"author": "withastro",

View file

@ -183,7 +183,26 @@ export async function renderComponent(
}
if (Component && (Component as any).isAstroComponentFactory) {
return renderToIterable(result, Component as any, _props, slots);
async function* renderAstroComponentInline(): AsyncGenerator<string, void, undefined> {
let iterable = await renderToIterable(result, Component as any, _props, slots);
// If this component added any define:vars styles and the head has already been
// sent out, we need to include those inline.
if (result.styles.size && alreadyHeadRenderedResults.has(result)) {
let styles = Array.from(result.styles);
result.styles.clear();
for (const style of styles) {
if ('define:vars' in style.props) {
// We only want to render the property value and not the full stylesheet
// which is bundled in the head.
style.children = '';
yield markHTMLString(renderElement('style', style));
}
}
}
yield* iterable;
}
return renderAstroComponentInline();
}
if (!Component && !_props['client:only']) {
@ -408,6 +427,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
island.children = `${html ?? ''}${template}`;
// Scripts to prepend
let prescriptType: PrescriptType = needsHydrationScript
? 'both'
: needsDirectiveScript
@ -655,6 +675,7 @@ export async function renderToIterable(
const Component = await componentFactory(result, props, children);
if (!isAstroComponent(Component)) {
// eslint-disable-next-line no-console
console.warn(
`Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.`
);
@ -719,6 +740,8 @@ export async function renderHead(result: SSRResult): Promise<string> {
const styles = Array.from(result.styles)
.filter(uniqueElements)
.map((style) => renderElement('style', style));
// Clear result.styles so that any new styles added will be inlined.
result.styles.clear();
const scripts = Array.from(result.scripts)
.filter(uniqueElements)
.map((script, i) => {

View file

@ -22,7 +22,7 @@ describe('Directives', async () => {
const html = await fixture.readFile('/define-vars/index.html');
const $ = cheerio.load(html);
expect($('style')).to.have.lengthOf(1);
expect($('style')).to.have.lengthOf(2);
expect($('style').toString()).to.include('--bg: white;');
expect($('style').toString()).to.include('--fg: black;');
@ -31,9 +31,18 @@ describe('Directives', async () => {
.split(' ')
.find((name) => /^astro-[A-Za-z0-9-]+/.test(name));
expect($('style').toString().replace(/\s+/g, '')).to.equal(
expect($($('style').get(0)).toString().replace(/\s+/g, '')).to.equal(
`<style>.${scopedClass}{--bg:white;--fg:black;}body{background:var(--bg);color:var(--fg)}</style>`
);
const scopedTitleClass = $('.title')
.attr('class')
.split(' ')
.find((name) => /^astro-[A-Za-z0-9-]+/.test(name));
expect($($('style').get(1)).toString().replace(/\s+/g, '')).to.equal(
`<style>.${scopedTitleClass}{--textColor:red;}</style>`
);
});
it('set:html', async () => {

View file

@ -0,0 +1,10 @@
---
const textColor = 'red'
---
<h1 class="title">hello there</h1>
<style define:vars={{textColor: textColor}}>
.title {
color: var(--textColor);
}
</style>

View file

@ -1,4 +1,5 @@
---
import Title from "../components/Title.astro"
let foo = 'bar'
let bg = 'white'
let fg = 'black'
@ -17,5 +18,7 @@ let fg = 'black'
<script id="inline" define:vars={{ foo }}>
console.log(foo);
</script>
<Title />
</body>
</html>

View file

@ -1,9 +0,0 @@
---
let gotError = false;
try {
Astro.response.headers = new Headers();
} catch(err) {
gotError = true;
}
---
<div id="overwrite-error">{gotError}</div>

View file

@ -1,3 +0,0 @@
---
Astro.response.headers.set('Seven-Eight', 'nine');
---

View file

@ -1,3 +0,0 @@
---
Astro.response.status = 403;
---

View file

@ -1,12 +0,0 @@
---
import SetStatus from '../components/SetStatus.astro';
---
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing</h1>
<SetStatus />
</body>
</html>

View file

@ -1,14 +0,0 @@
---
import SetAHeader from '../components/SetAHeader.astro';
import OverwriteHeader from '../components/OverwriteHeader.astro';
---
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1>Testing</h1>
<SetAHeader />
<OverwriteHeader />
</body>
</html>

View file

@ -1,5 +1,4 @@
---
import SetAHeader from '../components/SetAHeader.astro';
Astro.response.headers.set('One-Two', 'three');
Astro.response.headers.set('Four-Five', 'six');
---
@ -9,6 +8,5 @@ Astro.response.headers.set('Four-Five', 'six');
</head>
<body>
<h1>Testing</h1>
<SetAHeader />
</body>
</html>

View file

@ -32,13 +32,6 @@ describe('Using Astro.response in SSR', () => {
expect(response.statusText).to.equal('Oops');
});
it('Child component can set status', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/child-set-status');
const response = await app.render(request);
expect(response.status).to.equal(403);
});
it('Can add headers', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/some-header');
@ -46,17 +39,5 @@ describe('Using Astro.response in SSR', () => {
const headers = response.headers;
expect(headers.get('one-two')).to.equal('three');
expect(headers.get('four-five')).to.equal('six');
expect(headers.get('seven-eight')).to.equal('nine');
});
it('Child component cannot override headers object', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/child-tries-to-overwrite');
const response = await app.render(request);
const headers = response.headers;
expect(headers.get('seven-eight')).to.equal('nine');
const html = await response.text();
const $ = cheerioLoad(html);
expect($('#overwrite-error').html()).to.equal('true');
});
});

View file

@ -49,14 +49,14 @@ importers:
examples/basics:
specifiers:
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
astro: link:../../packages/astro
examples/blog:
specifiers:
'@astrojs/preact': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
preact: ^10.7.3
dependencies:
preact: 10.7.3
@ -67,7 +67,7 @@ importers:
examples/blog-multiple-authors:
specifiers:
'@astrojs/preact': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
preact: ^10.7.3
sass: ^1.52.2
dependencies:
@ -79,14 +79,14 @@ importers:
examples/component:
specifiers:
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
astro: link:../../packages/astro
examples/component/demo:
specifiers:
'@example/my-component': workspace:*
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
'@example/my-component': link:../packages/my-component
astro: link:../../../packages/astro
@ -102,7 +102,7 @@ importers:
'@docsearch/css': ^3.1.0
'@docsearch/react': ^3.1.0
'@types/react': ^17.0.45
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
preact: ^10.7.3
react: ^18.1.0
react-dom: ^18.1.0
@ -121,14 +121,14 @@ importers:
examples/env-vars:
specifiers:
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
astro: link:../../packages/astro
examples/framework-alpine:
specifiers:
alpinejs: ^3.10.2
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
dependencies:
alpinejs: 3.10.2
devDependencies:
@ -138,7 +138,7 @@ importers:
specifiers:
'@astrojs/lit': ^0.3.0
'@webcomponents/template-shadowroot': ^0.1.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
lit: ^2.2.5
dependencies:
'@webcomponents/template-shadowroot': 0.1.0
@ -156,7 +156,7 @@ importers:
'@astrojs/svelte': ^0.2.0
'@astrojs/vue': ^0.2.0
'@webcomponents/template-shadowroot': ^0.1.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
lit: ^2.2.5
preact: ^10.7.3
react: ^18.1.0
@ -185,7 +185,7 @@ importers:
examples/framework-preact:
specifiers:
'@astrojs/preact': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
preact: ^10.7.3
dependencies:
preact: 10.7.3
@ -198,7 +198,7 @@ importers:
'@astrojs/react': ^0.2.0
'@types/react': ^18.0.10
'@types/react-dom': ^18.0.5
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
react: ^18.1.0
react-dom: ^18.1.0
dependencies:
@ -213,7 +213,7 @@ importers:
examples/framework-solid:
specifiers:
'@astrojs/solid-js': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
solid-js: ^1.4.3
dependencies:
solid-js: 1.4.3
@ -224,7 +224,7 @@ importers:
examples/framework-svelte:
specifiers:
'@astrojs/svelte': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
svelte: ^3.48.0
dependencies:
svelte: 3.48.0
@ -235,7 +235,7 @@ importers:
examples/framework-vue:
specifiers:
'@astrojs/vue': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
vue: ^3.2.36
dependencies:
vue: 3.2.37
@ -253,7 +253,7 @@ importers:
'@astrojs/tailwind': ^0.2.1
'@astrojs/turbolinks': ^0.1.3
'@webcomponents/template-shadowroot': ^0.1.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
lit: ^2.2.5
preact: ^10.7.3
react: ^18.1.0
@ -282,20 +282,20 @@ importers:
examples/minimal:
specifiers:
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
astro: link:../../packages/astro
examples/non-html-pages:
specifiers:
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
astro: link:../../packages/astro
examples/portfolio:
specifiers:
'@astrojs/preact': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
preact: ^10.7.3
sass: ^1.52.2
dependencies:
@ -309,7 +309,7 @@ importers:
specifiers:
'@astrojs/node': ^0.1.2
'@astrojs/svelte': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
concurrently: ^7.2.1
lightcookie: ^1.0.25
svelte: ^3.48.0
@ -328,14 +328,14 @@ importers:
examples/starter:
specifiers:
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
astro: link:../../packages/astro
examples/subpath:
specifiers:
'@astrojs/react': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
react: ^18.1.0
react-dom: ^18.1.0
sass: ^1.52.2
@ -354,7 +354,7 @@ importers:
'@astrojs/react': ^0.2.0
'@astrojs/svelte': ^0.2.0
'@astrojs/vue': ^0.2.0
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
preact: ^10.7.3
react: ^18.1.0
react-dom: ^18.1.0
@ -377,7 +377,7 @@ importers:
examples/with-markdown-plugins:
specifiers:
'@astrojs/markdown-remark': ^0.11.3
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
hast-util-select: 5.0.1
rehype-autolink-headings: ^6.1.1
rehype-slug: ^5.0.1
@ -395,7 +395,7 @@ importers:
examples/with-markdown-shiki:
specifiers:
'@astrojs/markdown-remark': ^0.11.3
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
devDependencies:
'@astrojs/markdown-remark': link:../../packages/markdown/remark
astro: link:../../packages/astro
@ -410,7 +410,7 @@ importers:
'@nanostores/preact': ^0.1.3
'@nanostores/react': ^0.1.5
'@nanostores/vue': ^0.4.1
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
nanostores: ^0.5.12
preact: ^10.7.3
react: ^18.1.0
@ -438,7 +438,7 @@ importers:
examples/with-tailwindcss:
specifiers:
'@astrojs/tailwind': ^0.2.1
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
autoprefixer: ^10.4.7
canvas-confetti: ^1.5.1
postcss: ^8.4.14
@ -453,7 +453,7 @@ importers:
examples/with-vite-plugin-pwa:
specifiers:
astro: ^1.0.0-beta.56
astro: ^1.0.0-beta.57
vite-plugin-pwa: 0.11.11
workbox-window: ^6.5.3
devDependencies:
@ -8581,11 +8581,6 @@ packages:
/debug/3.2.7:
resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
dependencies:
ms: 2.1.3
dev: false
@ -11467,8 +11462,6 @@ packages:
debug: 3.2.7
iconv-lite: 0.4.24
sax: 1.2.4
transitivePeerDependencies:
- supports-color
dev: false
/netmask/2.0.2:
@ -11552,8 +11545,6 @@ packages:
rimraf: 2.7.1
semver: 5.7.1
tar: 4.4.19
transitivePeerDependencies:
- supports-color
dev: false
/node-releases/2.0.5: