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
{{ message }}
Repository navigation
On-demand content fetching / Dynamic imports (e.g. via RSC) #85
Currently Contentlayer is based on the assumption that all documents need to be statically fetched and processed as a build step "ahead of time". We should explore whether there's a way to do so dynamically at runtime.
As a first step we need to learn more about use cases that require this approach instead of static imports.
Notes
Related to "remote files source" (e.g. similar to next-mdx-remote)
Can be accelerated by avoiding file I/O (i.e. keep everything in-memory)
Might require a "in-memory" file system abstraction
Ideally there's a way to not fetch all content but just the required subset of data for a given page (might require some kind of "query API")
Should work in as many runtimes as possible (e.g. Node.js, Edge, ...) - related: Vercel runtime limits
the primary benefit of "new" jamstack approaches like remix and sveltekit is that pages are rendered on request, not all upfront. this makes the build time scalable for large sites. accordingly, it'd be nice to have the data requested on demand rather than upfront. (although i recognize that rendering time is probably a bigger chunk of build time than data compile time)
Not sure if this directly implies that documents need to be dynamically fetched, but there's definitely a need to compose documents at runtime. For example, a pretty popular way of handling navigation in digital gardens is to have interrelated notes "stack up" on a virtual desk, essentially ending up in a situation where you'd be able to have N documents open at the same time. (See the original example by Andy Matuschak.) Something like that is quite awkward to try and deal with statically (given the combinatorial explosion) — and is precisely why I've been tinkering with Contentlayer in combination with React Server Components. Granted, many such cases could be dealt with on the client side with some effort.
Thanks a lot for providing this perspective @sw-yx!
@bearror I think the use case you've described should already be very much possible to build. (In fact I'm planning to build something similar for myself - love Andy's notes system.) Feel free to ping me on Discord for further questions or if you need help.
Activity
swyxio commentedon Jan 3, 2022
the primary benefit of "new" jamstack approaches like remix and sveltekit is that pages are rendered on request, not all upfront. this makes the build time scalable for large sites. accordingly, it'd be nice to have the data requested on demand rather than upfront. (although i recognize that rendering time is probably a bigger chunk of build time than data compile time)
bearror commentedon Jan 3, 2022
Not sure if this directly implies that documents need to be dynamically fetched, but there's definitely a need to compose documents at runtime. For example, a pretty popular way of handling navigation in digital gardens is to have interrelated notes "stack up" on a virtual desk, essentially ending up in a situation where you'd be able to have N documents open at the same time. (See the original example by Andy Matuschak.) Something like that is quite awkward to try and deal with statically (given the combinatorial explosion) — and is precisely why I've been tinkering with Contentlayer in combination with React Server Components. Granted, many such cases could be dealt with on the client side with some effort.
schickling commentedon Jan 4, 2022
Thanks a lot for providing this perspective @sw-yx!
@bearror I think the use case you've described should already be very much possible to build. (In fact I'm planning to build something similar for myself - love Andy's notes system.) Feel free to ping me on Discord for further questions or if you need help.
[-]Dynamic imports[/-][+]On-demand content fetching / Dynamic imports (e.g. via RSC)[/+]schickling commentedon Mar 28, 2023
This should be addressed with the
0.3.1release. 🎉swyxio commentedon Mar 30, 2023
thats hot!