You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A low-level hook into the rendering process that allows a component to affect response headers and <head> rendering.
Background & Motivation
Due to Astro's streaming, we only wait until the page's frontmatter has run before generating the element. Frontmatter of a component cannot add scripts or stylesheets because by the time it's run, the is already sent to the browser so that it can start loading assets.
This becomes an issue when a component uses the content collections API. The render() call adds styles and scripts relevant to the content entry to the <head> element. Therefore, it must be used nowhere other than the routed page's frontmatter, as that would lead to missing assets: withastro/astro#7761.
Goals
Allow components to use content collections.
Allow components to change response headers and status.
The above example is from the reproduction of the meta-issue withastro/astro#7761. An array of component render results has been passed to Astro.waitFor(). Each one of them should be able to mutate the Astro.response object and allow contentEntry.render() to add required assets to the <head> element.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
A low-level hook into the rendering process that allows a component to affect response headers and
<head>
rendering.Background & Motivation
Due to Astro's streaming, we only wait until the page's frontmatter has run before generating the element. Frontmatter of a component cannot add scripts or stylesheets because by the time it's run, the is already sent to the browser so that it can start loading assets.
This becomes an issue when a component uses the content collections API. The
render()
call adds styles and scripts relevant to the content entry to the<head>
element. Therefore, it must be used nowhere other than the routed page's frontmatter, as that would lead to missing assets: withastro/astro#7761.Goals
Example
The above example is from the reproduction of the meta-issue withastro/astro#7761. An array of component render results has been passed to
Astro.waitFor()
. Each one of them should be able to mutate theAstro.response
object and allow contentEntry.render() to add required assets to the<head>
element.Alternative
export const addsToHead
in the component.For
Against
Beta Was this translation helpful? Give feedback.
All reactions