From 3cd5a7f53f28d7cb417650c1cdafeb17632ea6a2 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 8 Oct 2021 15:15:03 -0400 Subject: [PATCH] [next] support Astro.slots API (#1516) --- packages/astro/package.json | 2 +- packages/astro/src/runtime/ssr.ts | 5 ++++- packages/astro/test/astro-slots.test.js | 6 +++--- .../slottedapi-default-filled.astro} | 0 .../slottedapi-empty.astro} | 0 .../slottedapi-filled.astro} | 0 yarn.lock | 8 ++++---- 7 files changed, 12 insertions(+), 9 deletions(-) rename packages/astro/test/fixtures/astro-slots/src/{skipped/slottedapi-default-filled.astro.skip => pages/slottedapi-default-filled.astro} (100%) rename packages/astro/test/fixtures/astro-slots/src/{skipped/slottedapi-empty.astro.skip => pages/slottedapi-empty.astro} (100%) rename packages/astro/test/fixtures/astro-slots/src/{skipped/slottedapi-filled.astro.skip => pages/slottedapi-filled.astro} (100%) diff --git a/packages/astro/package.json b/packages/astro/package.json index b56f2cbba..68eadeeaf 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -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", diff --git a/packages/astro/src/runtime/ssr.ts b/packages/astro/src/runtime/ssr.ts index 8b4dde7f7..cf7d92460 100644 --- a/packages/astro/src/runtime/ssr.ts +++ b/packages/astro/src/runtime/ssr.ts @@ -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 | 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 }, diff --git a/packages/astro/test/astro-slots.test.js b/packages/astro/test/astro-slots.test.js index 6778a6b9e..3b4b11c22 100644 --- a/packages/astro/test/astro-slots.test.js +++ b/packages/astro/test/astro-slots.test.js @@ -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); diff --git a/packages/astro/test/fixtures/astro-slots/src/skipped/slottedapi-default-filled.astro.skip b/packages/astro/test/fixtures/astro-slots/src/pages/slottedapi-default-filled.astro similarity index 100% rename from packages/astro/test/fixtures/astro-slots/src/skipped/slottedapi-default-filled.astro.skip rename to packages/astro/test/fixtures/astro-slots/src/pages/slottedapi-default-filled.astro diff --git a/packages/astro/test/fixtures/astro-slots/src/skipped/slottedapi-empty.astro.skip b/packages/astro/test/fixtures/astro-slots/src/pages/slottedapi-empty.astro similarity index 100% rename from packages/astro/test/fixtures/astro-slots/src/skipped/slottedapi-empty.astro.skip rename to packages/astro/test/fixtures/astro-slots/src/pages/slottedapi-empty.astro diff --git a/packages/astro/test/fixtures/astro-slots/src/skipped/slottedapi-filled.astro.skip b/packages/astro/test/fixtures/astro-slots/src/pages/slottedapi-filled.astro similarity index 100% rename from packages/astro/test/fixtures/astro-slots/src/skipped/slottedapi-filled.astro.skip rename to packages/astro/test/fixtures/astro-slots/src/pages/slottedapi-filled.astro diff --git a/yarn.lock b/yarn.lock index f14440424..242ebf609 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"