0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-24 23:21:57 -05:00

fix: Cannot read properties of null (reading 'Symbol(astro.headAndContent)') (#11839)

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
Ion Căliman 2024-10-19 06:02:50 +03:00 committed by GitHub
parent a75bc5e306
commit ff522b96a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes error when returning a top-level `null` from an Astro file frontmatter

View file

@ -9,7 +9,7 @@ export type HeadAndContent = {
};
export function isHeadAndContent(obj: unknown): obj is HeadAndContent {
return typeof obj === 'object' && !!(obj as any)[headAndContentSym];
return typeof obj === 'object' && obj !== null && !!(obj as any)[headAndContentSym];
}
export function createHeadAndContent(head: string, content: RenderTemplateResult): HeadAndContent {

View file

@ -101,5 +101,5 @@ export function createAstroComponentInstance(
}
export function isAstroComponentInstance(obj: unknown): obj is AstroComponentInstance {
return typeof obj === 'object' && !!(obj as any)[astroComponentInstanceSym];
return typeof obj === 'object' && obj !== null && !!(obj as any)[astroComponentInstanceSym];
}

View file

@ -57,7 +57,7 @@ export class RenderTemplateResult {
// Determines if a component is an .astro component
export function isRenderTemplateResult(obj: unknown): obj is RenderTemplateResult {
return typeof obj === 'object' && !!(obj as any)[renderTemplateResultSym];
return typeof obj === 'object' && obj !== null && !!(obj as any)[renderTemplateResultSym];
}
export function renderTemplate(htmlParts: TemplateStringsArray, ...expressions: any[]) {

View file

@ -108,4 +108,43 @@ describe('core/render components', () => {
},
);
});
it('should render component with `null` response', async () => {
const fixture = await createFixture({
'/src/pages/index.astro': `
---
import NullComponent from '../components/NullComponent.astro';
---
<NullComponent />
`,
'/src/components/NullComponent.astro': `
---
return null;
---
`,
});
await runInContainer(
{
inlineConfig: {
root: fixture.path,
logLevel: 'silent',
},
},
async (container) => {
const { req, res, done, text } = createRequestAndResponse({
method: 'GET',
url: '/',
});
container.handle(req, res);
await done;
const html = await text();
const $ = cheerio.load(html);
assert.equal($('body').text(), '');
assert.equal(res.statusCode, 200);
},
);
});
});