Skip to content
Closed
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/great-pugs-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an internal bug where in some cases the head propagation wasn't correctly flagged.
11 changes: 11 additions & 0 deletions packages/astro/src/runtime/server/render/astro/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ export function isAPropagatingComponent(
}
return hint === 'in-tree' || hint === 'self';
}

export function getPropagationHint(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have this same function somewhere else? Or is it different? If the same we should reuse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other function is in the same file, few lines up. It's different and it checks if hint === 'in-tree' || hint === 'self'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that function use this one then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

result: SSRResult,
factory: AstroComponentFactory,
): PropagationHint {
let hint: PropagationHint = factory.propagation || 'none';
if (factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === 'none') {
hint = result.componentMetadata.get(factory.moduleId)!.propagation;
}
return hint;
}
4 changes: 3 additions & 1 deletion packages/astro/src/runtime/server/render/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isAstroComponentFactory } from './astro/index.js';
import { renderToAsyncIterable, renderToReadableStream, renderToString } from './astro/render.js';
import { encoder } from './common.js';
import { isDeno, isNode } from './util.js';
import { getPropagationHint } from './astro/factory.js';

export async function renderPage(
result: SSRResult,
Expand Down Expand Up @@ -43,8 +44,9 @@ export async function renderPage(

// Mark if this page component contains a <head> within its tree. If it does
// We avoid implicit head injection entirely.
const propagationHint = getPropagationHint(result, componentFactory);
result._metadata.headInTree =
result.componentMetadata.get(componentFactory.moduleId!)?.containsHead ?? false;
result.componentMetadata.get(componentFactory.moduleId!)?.containsHead ?? propagationHint === 'in-tree';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be checking for propagationHint === 'self'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems not. When working with propagation, the Astro engine assigns in-tree hint when a server island is used inside a component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking about it again, the headInTree variable is intended to be used to know if the <head> element is anywhere in the tree of components. That is the actual <head> tag. It's not intended to be used to know if we should do head propagation.

The purpose is to support cases where there is no explicit <head> element used in the page (a legacy mistake, imo).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm OK. I will create a different flag then, Thank you for your comments!


let body: BodyInit | Response;
if (streaming) {
Expand Down