Skip to content

Conversation

@ematipico
Copy link
Member

@ematipico ematipico commented May 9, 2025

Changes

While working with CSP and server islands, I found out that we don't use the PropagationHint to determine if the head is the tree of the components or not.

As explained here:

/**
* A hint on whether the Astro runtime needs to wait on a component to render head
* content. The meanings:
*
* - __none__ (default) The component does not propagation head content.
* - __self__ The component appends head content.
* - __in-tree__ Another component within this component's dependency tree appends head content.
*
* These are used within the runtime to know whether or not a component should be waited on.
*/
export type PropagationHint = 'none' | 'self' | 'in-tree';

The in-tree hint should signal our rendering engine if there's a component that we must wait, so it can render the head. The wasn't done in the code base. When I added the check, I could see the server island was correctly awaited, and eventually the head was rendered.

I preferred to send the fix here because it's unrelated to the work I've been doing.

Testing

I tested it manually. We don't have special components that would trigger situation for now, so the CI should stay green.

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented May 9, 2025

🦋 Changeset detected

Latest commit: 35fcf1b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label May 9, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 9, 2025

CodSpeed Performance Report

Merging #13776 will not alter performance

Comparing fix/head-propagation (35fcf1b) with main (1552dcb)

Summary

✅ 6 untouched benchmarks

@ematipico ematipico marked this pull request as ready for review May 9, 2025 12:33
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!

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!

@ematipico ematipico requested a review from matthewp May 9, 2025 13:24
@ematipico ematipico closed this May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants