[next] support Astro.slots API (#1516)

This commit is contained in:
Matthew Phillips 2021-10-08 15:15:03 -04:00 committed by Drew Powers
parent 1bd3cf8f4d
commit 3cd5a7f53f
7 changed files with 12 additions and 9 deletions

View file

@ -40,7 +40,7 @@
"test": "mocha --parallel --timeout 15000"
},
"dependencies": {
"@astrojs/compiler": "^0.1.0-canary.47",
"@astrojs/compiler": "^0.1.9",
"@astrojs/language-server": "^0.7.16",
"@astrojs/markdown-remark": "^0.3.1",
"@astrojs/markdown-support": "0.3.1",

View file

@ -167,7 +167,7 @@ export async function ssr({ astroConfig, filePath, logging, mode, origin, pathna
styles: new Set(),
scripts: new Set(),
/** This function returns the `Astro` faux-global */
createAstro: (props: any) => {
createAstro: (props: any, slots: Record<string, any> | null) => {
const site = new URL(origin);
const url = new URL('.' + pathname, site);
const canonicalURL = getCanonicalURL(pathname, astroConfig.buildOptions.site || origin);
@ -178,6 +178,9 @@ export async function ssr({ astroConfig, filePath, logging, mode, origin, pathna
request: { url, canonicalURL },
props,
fetchContent,
slots: Object.fromEntries(
Object.entries(slots || {}).map(([slotName]) => [slotName, true])
)
};
},
_metadata: { importedModules, renderers },

View file

@ -65,7 +65,7 @@ describe('Slots', () => {
expect($('#default').children('astro-component')).to.have.lengthOf(1);
});
it.skip('Slots API work on Components', async () => {
it('Slots API work on Components', async () => {
// IDs will exist whether the slots are filled or not
{
const html = await fixture.readFile('/slottedapi-default/index.html');
@ -90,7 +90,7 @@ describe('Slots', () => {
// IDs will exist because the slots are filled
{
const html = await fixture.fetch('/slottedapi-filled/index.html');
const html = await fixture.readFile('/slottedapi-filled/index.html');
const $ = cheerio.load(html);
expect($('#a')).to.have.lengthOf(1);
@ -102,7 +102,7 @@ describe('Slots', () => {
// Default ID will exist because the default slot is filled
{
const html = await fixture.fetch('/slottedapi-default-filled/index.html');
const html = await fixture.readFile('/slottedapi-default-filled/index.html');
const $ = cheerio.load(html);
expect($('#a')).to.have.lengthOf(0);

View file

@ -106,10 +106,10 @@
"@algolia/logger-common" "4.10.5"
"@algolia/requester-common" "4.10.5"
"@astrojs/compiler@^0.1.0-canary.47":
version "0.1.0-canary.47"
resolved "https://registry.yarnpkg.com/@astrojs/compiler/-/compiler-0.1.0-canary.47.tgz#377c95d49b2a3791c78077796de0f2ea342177d0"
integrity sha512-Tr2oFNyIMuVpiQnDPAKbeAjKCbFRlpugqFjz8zdkjxazfM+ZxbRUji5NJ8jPJwEGcL2Td3zUBFzA2H+WBiNnhA==
"@astrojs/compiler@^0.1.9":
version "0.1.9"
resolved "https://registry.yarnpkg.com/@astrojs/compiler/-/compiler-0.1.9.tgz#079f8618f4281f07421c961aa2161cb3ab771b4d"
integrity sha512-cFdAsjLUG9q5mwyXexKHZIWSMKacQgLkzQJuHm5kqCd6u+Njl+/iXbxsTAAkNu5L6MNM/kipezfthHppC5TRgA==
dependencies:
typescript "^4.3.5"