contentlayerdev / contentlayer

Contentlayer turns your content into data - making it super easy to import MD(X) and CMS content in your app
https://www.contentlayer.dev
MIT License
3.31k stars 202 forks source link

On-demand content fetching / Dynamic imports (e.g. via RSC) #85

Closed schickling closed 1 year ago

schickling commented 2 years ago

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

swyxio commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.

schickling commented 1 year ago

This should be addressed with the 0.3.1 release. 🎉

swyxio commented 1 year ago

thats hot!