-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Document glob() loader deferRender option #14208
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,7 @@ For simple data fetching, you can also [define a loader as an async function](#d | |||||
|
|
||||||
| The `glob()` loader creates entries from directories of files from anywhere on the filesystem. The supported file types are Markdown, MDX, Markdoc, JSON, YAML, and TOML files. | ||||||
|
|
||||||
| This loader accepts an object with the following properties: `pattern`, `base` (optional), `generateId` (optional), and `retainBody` (optional). | ||||||
| This loader accepts an object with the following properties: `pattern`, `base` (optional), `generateId` (optional), `retainBody` (optional), and `deferRender` (optional). | ||||||
|
|
||||||
| ```ts title="src/content.config.ts" | ||||||
| import { defineCollection } from 'astro:content'; | ||||||
|
|
@@ -124,6 +124,34 @@ For Markdown files, the rendered body will still be available in the [`entry.ren | |||||
|
|
||||||
| For MDX collections, this will dramatically reduce the size of the collection, as there will no longer be any body retained in the store. | ||||||
|
|
||||||
| #### `deferRender` | ||||||
|
|
||||||
| <p> | ||||||
|
|
||||||
| **Type:** `boolean`<br /> | ||||||
| **Default:** `false` | ||||||
| <Since v="7.1.0" /> | ||||||
| </p> | ||||||
|
|
||||||
| Whether to defer rendering of renderable entries (such as Markdown) until they are rendered in a page, instead of rendering them eagerly during content sync. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I included Yan suggestion (mentioning MDX) but something is still not clear to me. Does this affects MDX ("using the same on-demand rendering path that Nonetheless, I think the last sentence should be moved here as it clearly states what is affected and what's not. And I think this also helps a bit with "rendering of renderable... rendered... rendering" which sounds heavy to me in a single sentence.
Suggested change
It might not be perfect... as a non native speaker, I would have used "displayed" instead of "rendered" for the second occurrence in the first sentence. But, maybe "rendered" carry an important nuance. And whether we use |
||||||
|
|
||||||
| By default, the `glob()` loader renders each Markdown entry during sync and stores the resulting HTML in the data store. This allows the rendered content to be cached and reused across builds. However, for large collections whose rendered output is much larger than the source, storing all this rendered HTML in memory at once can cause your build to run out of memory. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
would this mean this has some interaction with the |
||||||
|
|
||||||
| When `deferRender` is `true`, rendering is instead deferred until each entry is actually rendered in a page, using the same on-demand rendering path that `.mdx` files already use. This keeps memory usage bounded during `astro build` at the cost of the rendered HTML no longer being cached in the data store. | ||||||
|
|
||||||
| ```ts title="src/content.config.ts" | ||||||
| const docs = defineCollection({ | ||||||
| /* Defer rendering of a large Markdown collection to avoid running out of memory during the build. */ | ||||||
| loader: glob({ | ||||||
| pattern: '**/*.md', | ||||||
| base: './src/data/docs', | ||||||
| deferRender: true, | ||||||
| }), | ||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| This option only affects renderable entries. Data entries (such as JSON, YAML, and TOML files) are unaffected. | ||||||
|
Comment on lines
+152
to
+153
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if you agree with my first suggestion, this means we can delete this:
Suggested change
|
||||||
|
|
||||||
| ### `file()` loader | ||||||
|
|
||||||
| <p> | ||||||
|
|
||||||
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.
I would mention MDX up top so its clear from the get go it benefits both.