-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Container APIs #916
base: main
Are you sure you want to change the base?
Container APIs #916
Conversation
Co-authored-by: Matthew Phillips <matthew@skypack.dev>
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
} | ||
``` | ||
|
||
The `astroConfig` object is literally the same object exposed by the `defineConfig`, inside the `astro.config.mjs` file. This very configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you found use-case for passing the astroConfig yet? I'm worried about getting bug reports when people try to pass through vite
config and other non-supported stuff.
What do you think about instead raising the relevant config values up to the AstroContainerOptions
level. That would be stuff like trailingSlash
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about instead raising the relevant config values up to the AstroContainerOptions level. That would be stuff like trailingSlash.
I don't think that would work easily. These options, internally, are used to create a manifest. If we pass these options when rendering a component, it would mean generating a new manifest every time we attempt to render a component, and then discard that manifest. We have to be careful not to override the existing manifest, because the manifest is tight to the lifetime of the instance of the container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not when rendering, AstroContainerOptions
is the name of the options passed to AstroContainer.create()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I misunderstood what you meant. Yeah we should be able to provide the individual options.
Hey! Can I use the new container API to render I tried passing const rawPages = await getCollection('posts')
const sortedPages = rawPages.sort((a, b) => a.data.order - b.data.order)
const pages: RadnetzPage[] = []
for (const page of sortedPages) {
const { Content } = await page.render()
const container = await AstroContainer.create()
const result = await container.renderToString(Content)
pages.push({
slug: page.slug,
menu: page.data.menu,
order: page.data.order,
title: page.data.title,
links: page.data.links,
Content: Content,
contentHtml: result,
})
} Results in…
(I was directed here from the changelog.) |
@tordans yes you can, however you'll have to wait for this PR to be merged and released: withastro/astro#11141 |
Perfect, thanks @ematipico. |
d1a5400
to
a5e85d0
Compare
Can I use this in a Cloudflare project? It currently throws an error during build.
I am using the MDX renderer specifically to render |
@universse it's hard to tell to give you an answer with this little information. Please use Discord. |
const { Content } = await entry.render()
const descriptionHtml = await astroContainer.renderToString(Content) I'm using Astro container to render Update: adding these to Astro config works for me. {
vite: {
ssr: {
external: ['astro/container', '@astrojs/mdx'],
},
},
} Update 2: when deployed, only pre-rendered page works. server-rendered page will give status 500. |
Will the proposed I’m wondering if it’ll be possible to create a custom framework on top of Astro, e.g. with one’s own pages setup; or say, rendering Astro as an endpoint alongside another Vite site. |
@alidcast If you run the container inside a Vite environment, then yes, all your |
Hi. I've been using the While script tags and scoped style tags appear to work correctly, the use of imported css modules will not be rendered via renderToString(), regardless if the existence of a head tag. This could be sometimes useful. For example when rendering html for injection into the content:encoded tag of RSS or copying strings into JS variables that only needs the rendered HTML. However, if rendering for the purposes of being placing on a page, the loss of styles is a showstopper. I didn't see any setting that controlled whether or not to inject module style tags in the container docs. |
This hasn't been implemented because we failed to find a valid use case. You just mentioned RSS, JS variables and such. Since we are evaluating a real use case, it would be amazing if you could go in detail and explain to me what you're looking for, and if you'd explain me very well you use case. |
@ematipico Scenario 1: Creating a page at
|
Yes @dwighthouse's post is excellent. You can see how we are forced to use |
I wanted to add my use case for accessing styles, I have a portfolio site with resume/CV component I've made and wish to display it on page differently than download versions only need component with styles while page has layout and supplies styles to show more pretty. |
Summary
An API for rendering components in isolation:
Links