Skip to content

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

Closed

Description

@schickling

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
    • Might require some kind of "content CDN"
  • multi-threaded data sharing

Activity

  1. swyxio commented on Jan 3, 2022

    @swyxio

    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)

  2. bearror commented on Jan 3, 2022

    @bearror

    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.

  3. schickling commented on Jan 4, 2022

    @schickling
    CollaboratorAuthor

    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.

  4. changed the title [-]Dynamic imports[/-] [+]On-demand content fetching / Dynamic imports (e.g. via RSC)[/+] on Jan 17, 2023
  5. added this to the Pre-1.0 milestone on Jan 17, 2023
  6. modified the milestones: Pre-1.0, 0.3.1 on Mar 28, 2023
  7. schickling commented on Mar 28, 2023

    @schickling
    CollaboratorAuthor

    This should be addressed with the 0.3.1 release. 🎉

  8. swyxio commented on Mar 30, 2023

    @swyxio

    thats hot!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuremore-info-needed

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions