Git Product home page Git Product logo

Comments (6)

ryanflorence avatar ryanflorence commented on May 4, 2024 1

Michael and I discussed this recently and realized there are some assumptions and optimizations we don't want to give up in order to do this.

We'd need to stop fetching data in parallel from the browser on navigation because it'd be impossible to bridge the gap from the browser fetch requests to awaiting a parent's data in a child loader on the server, they're happening in different worlds (different requests to the server). We'd need to fetch all data from a single URL on each request.

We also have some fuzzy ideas about fetching from other places than the remix server, so we don't want to tie ourselves to the remix data endpoint too much yet. Right now the we only fetch data for changed routes and that logic lives in the browser code. We'd need to move that to the server code and we're not ready for it yet.

So for now, if you need the same data in nested routes, just fetch it in both loaders. We understand that's double the work in some cases, but also remember that it's also less work in the case your'e navigating to the same child route with different params. If you awaited the parent loader, and it fetches more stuff than the child needs, you'd be fetching all of that every time the params change.

As usual, trade offs!

We've got some whacky streaming ideas for this where we might be able to have our cake and eat it too, but we're not there yet.

from remix.

richardscarrott avatar richardscarrott commented on May 4, 2024 1

Ok, just found this in the examples https://github.com/remix-run/remix/tree/main/examples/dataloader which a) does use dataloader to solve this issue and b) does store the data loaders on context.

UPDATED LINK: https://github.com/remix-run/examples/tree/main/dataloader

from remix.

johnsonthedev avatar johnsonthedev commented on May 4, 2024

thanks for the update and that you have looked at it. it was actually one of the features I was mostly waiting for (besides HMR :-P ) fingers crossed that we find a solution one day

from remix.

RoyalIcing avatar RoyalIcing commented on May 4, 2024

Is there a way to take advantage of HTTP caching somehow to have say a cache time of 60 seconds, and so the child would actually reuse the cached response made originally in the parent? @ryanflorence

from remix.

richardscarrott avatar richardscarrott commented on May 4, 2024

@ryanflorence I wonder if something like data loader would be beneficial for the initial HTML request so that, if a parent and child route both need to fetch the user, they'd only make a single DB call. They'd additionally benefit from batching if the parent needed user A and a child user B etc.

I'm only just getting started with remix, but looks like remix loader context might be a suitable place to store a request-level data loader cache?

Aside, the name is unfortunate πŸ˜†

from remix.

acusti avatar acusti commented on May 4, 2024

i stumbled across this issue looking for how to get parent data into a child route component (not a child’s loader). to save time for anyone else looking for that as well: you can get the data from all parent routes in a child route by using the useMatches hook.

from remix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.