Fix: recursive getCollection()
hanging (#6257)
* fix: avoid trying to SSR md?astroPropagatedAssets * test: layout prop with recursive getCollection * chore: changeset
This commit is contained in:
parent
802ae458fe
commit
2fec478487
6 changed files with 88 additions and 1 deletions
5
.changeset/metal-ducks-invite.md
Normal file
5
.changeset/metal-ducks-invite.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix: prevent dev server hanging for `getCollection()` calls within a layout when using the `layout` prop
|
|
@ -60,7 +60,16 @@ export async function* crawlGraph(
|
|||
if (entryIsStyle && !isCSSRequest(importedModulePathname)) {
|
||||
continue;
|
||||
}
|
||||
if (fileExtensionsToSSR.has(npath.extname(importedModulePathname))) {
|
||||
if (
|
||||
fileExtensionsToSSR.has(
|
||||
npath.extname(
|
||||
// Use `id` instead of `pathname` to preserve query params.
|
||||
// Should not SSR a module with an unexpected query param,
|
||||
// like "?astroPropagatedAssets"
|
||||
importedModule.id
|
||||
)
|
||||
)
|
||||
) {
|
||||
const mod = loader.getModuleById(importedModule.id);
|
||||
if (!mod?.ssrModule) {
|
||||
try {
|
||||
|
|
|
@ -191,5 +191,24 @@ describe('Content Collections - render()', () => {
|
|||
expect(h2).to.have.a.lengthOf(1);
|
||||
expect(h2.attr('data-components-export-applied')).to.equal('true');
|
||||
});
|
||||
|
||||
it('Supports layout prop with recursive getCollection() call', async () => {
|
||||
const response = await fixture.fetch('/with-layout-prop', { method: 'GET' });
|
||||
expect(response.status).to.equal(200);
|
||||
|
||||
const html = await response.text();
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const body = $('body');
|
||||
expect(body.attr('data-layout-prop')).to.equal('true');
|
||||
|
||||
const h1 = $('h1');
|
||||
expect(h1).to.have.a.lengthOf(1);
|
||||
expect(h1.text()).to.equal('With Layout Prop');
|
||||
|
||||
const h2 = $('h2');
|
||||
expect(h2).to.have.a.lengthOf(1);
|
||||
expect(h2.text()).to.equal('Content with a layout prop');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
38
packages/astro/test/fixtures/content/src/components/LayoutProp.astro
vendored
Normal file
38
packages/astro/test/fixtures/content/src/components/LayoutProp.astro
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
---
|
||||
import { CollectionEntry, getCollection } from 'astro:content';
|
||||
|
||||
// Test for recursive `getCollection()` calls
|
||||
const blog = await getCollection('blog');
|
||||
|
||||
type Props = {
|
||||
content: CollectionEntry<'blog'>['data'];
|
||||
};
|
||||
|
||||
const {
|
||||
content: { title },
|
||||
} = Astro.props;
|
||||
---
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>With Layout Prop</title>
|
||||
</head>
|
||||
<body data-layout-prop="true">
|
||||
<h1>{title}</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
{blog.map((post) => (
|
||||
<li>
|
||||
<a href={post.slug}>{post.data.title}</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</nav>
|
||||
<slot />
|
||||
</body>
|
||||
</html>
|
||||
|
9
packages/astro/test/fixtures/content/src/content/blog/with-layout-prop.md
vendored
Normal file
9
packages/astro/test/fixtures/content/src/content/blog/with-layout-prop.md
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: With Layout Prop
|
||||
description: Use a layout prop in a content collection
|
||||
layout: "../../components/LayoutProp.astro"
|
||||
---
|
||||
|
||||
## Content with a layout prop
|
||||
|
||||
Sure, why not?
|
7
packages/astro/test/fixtures/content/src/pages/with-layout-prop.astro
vendored
Normal file
7
packages/astro/test/fixtures/content/src/pages/with-layout-prop.astro
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
import { getEntryBySlug } from 'astro:content';
|
||||
|
||||
const entry = await getEntryBySlug('blog', 'with-layout-prop');
|
||||
const { Content } = await entry.render();
|
||||
---
|
||||
<Content />
|
Loading…
Reference in a new issue