Skip to content

feat: add renderComponent - #14592

Open
ematipico wants to merge 1 commit into
mainfrom
feat/add-render-component
Open

ematipico wants to merge 1 commit into
mainfrom
feat/add-render-component

Conversation

@ematipico

Copy link
Copy Markdown
Member

Description (required)

It documents a new renderComponent function in the Astro container APIs

References

Ref withastro/astro#17736

@ematipico ematipico added the merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) label Sep 21, 2026
@astrobot-houston

Copy link
Copy Markdown
Contributor

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the tracking.ignoredKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
reference/container-reference.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown

Preview deployment

✅ Deployment complete!

@ArmandPhilippot ArmandPhilippot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, Ema! Except the API block that contains a few issues, my other suggestions are mostly nit. I also left a question about <script /> tags behavior.

Comment on lines +182 to +184
**Type:** <code>(component: AstroComponentFactory; options?: <a href="#rendering-options">ContainerRenderOptions</a>) => Promise&lt;Response&gt;</code>
</p>
<p><Since v="7.3.4" /></p>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • consistency: We want them in the same block, not two paragraphs
  • This seems to return Promise<string> and not Promise<Response>, which makes more sense if it returns HTML
  • It doesn't seem to accept routeType as option

See: https://github.com/withastro/astro/blob/88606470c4fe267f86959565f47c61c80b513649/packages/astro/src/container/index.ts#L569-L572

Suggested change
**Type:** <code>(component: AstroComponentFactory; options?: <a href="#rendering-options">ContainerRenderOptions</a>) => Promise&lt;Response&gt;</code>
</p>
<p><Since v="7.3.4" /></p>
**Type:** <code>(component: AstroComponentFactory; options?: Omit\<<a href="#rendering-options">ContainerRenderOptions</a>, 'routeType'\>) => Promise&lt;string&gt;</code><br />
<Since v="7.3.4" />
</p>

</p>
<p><Since v="7.3.4" /></p>

It renders a component, and returns its HTML with script and styles. The Astro component must be imported with the query string `?container`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we usually try to avoid restating what the function name already says (ie. "renderComponent(): it renders a component"), but it's tricky when the function name is well chosen... And, I can see some other methods on the page already use similar wording, so not blocking.

But if we want to update that, maybe something like the following could work:

Suggested change
It renders a component, and returns its HTML with script and styles. The Astro component must be imported with the query string `?container`.
A function that returns the HTML for a component, including its scripts and styles. It takes an Astro component imported with the `?container` query string as an argument.


It renders a component, and returns its HTML with script and styles. The Astro component must be imported with the query string `?container`.

The container will only render the styles declared in the `<style>` element, and the scripts declared in the `<script>` element. Assets imported via `import` are not rendered.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: does it works <script src="./any-script.ts"></script> (does the path is resolved/transpiled?) or is it considered the same as import statements?


```

Omitting the `?container` query string will result in the same output as [`renderToString()`](#rendertostring)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: missing period

Suggested change
Omitting the `?container` query string will result in the same output as [`renderToString()`](#rendertostring)
Omitting the `?container` query string will result in the same output as [`renderToString()`](#rendertostring).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants