Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-poets-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/compiler": patch
---

Fixes a potential parsing issue with head content defined in a component where another component is rendered first.
2 changes: 1 addition & 1 deletion internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ func inBodyIM(p *parser) bool {
case a.Br:
p.tok.Type = StartTagToken
return false
case a.Template:
case a.Base, a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Script, a.Style, a.Template, a.Title:
return inHeadIM(p)
default:
p.inBodyEndTagOther(p.tok.DataAtom, p.tok.Data)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

[TestPrinter/head_content_with_component_first - 1]
## Input

```
/-/-/-/
import Analytics from '../components/Analytics.astro';
/-/-/-/
<Analytics />
<title>{title}</title>
<meta name="description" content="a description" />
```

## Output

```js
import {
Fragment,
render as $$render,
createAstro as $$createAstro,
createComponent as $$createComponent,
renderComponent as $$renderComponent,
renderHead as $$renderHead,
maybeRenderHead as $$maybeRenderHead,
unescapeHTML as $$unescapeHTML,
renderSlot as $$renderSlot,
mergeSlots as $$mergeSlots,
addAttribute as $$addAttribute,
spreadAttributes as $$spreadAttributes,
defineStyleVars as $$defineStyleVars,
defineScriptVars as $$defineScriptVars,
renderTransition as $$renderTransition,
createTransitionScope as $$createTransitionScope,
renderScript as $$renderScript,
createMetadata as $$createMetadata
} from "http://localhost:3000/";
import Analytics from '../components/Analytics.astro';

import * as $$module1 from '../components/Analytics.astro';

export const $$metadata = $$createMetadata(import.meta.url, { modules: [{ module: $$module1, specifier: '../components/Analytics.astro', assert: {} }], hydratedComponents: [], clientOnlyComponents: [], hydrationDirectives: new Set([]), hoisted: [] });

const $$Component = $$createComponent(($$result, $$props, $$slots) => {

return $$render`${$$renderComponent($$result,'Analytics',Analytics,{})}
<title>${title}</title>
<meta name="description" content="a description">`;
}, undefined, undefined);
export default $$Component;
```
---
9 changes: 9 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,15 @@ const meta = { title: 'My App' };
name: "namespace is preserved when inside an expression",
source: `<svg>{<image />}</svg>`,
},
{
name: "head content with component first",
source: `---
import Analytics from '../components/Analytics.astro';
---
<Analytics />
<title>{title}</title>
<meta name="description" content="a description" />`,
},
}
for _, tt := range tests {
if tt.only {
Expand Down
Loading