Skip to content

Commit

Permalink
[next] support Astro.slots API (#1516)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and drwpow committed Oct 22, 2021
1 parent 1bd3cf8 commit 3cd5a7f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/src/runtime/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 },
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/astro-slots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 3cd5a7f

Please sign in to comment.