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:
parent
a75bc5e306
commit
ff522b96a0
5 changed files with 47 additions and 3 deletions
5
.changeset/twelve-moose-cough.md
Normal file
5
.changeset/twelve-moose-cough.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes error when returning a top-level `null` from an Astro file frontmatter
|
|
@ -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 {
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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[]) {
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue