#Should parent loader run when moving from child to parent route

1 messages · Page 1 of 1 (latest)

vernal sequoia
#

Should parent loader run when moving from child to parent route

wispy ferry
#

When you navigate to the parent, it's not the parent anymore, and Remix will run loaders for the current route

vernal sequoia
#

Okay that makes sense. Thanks Jacob 🙂

#

But doesn't that hold true for parent to child navigation as well? Or does in that case, remix knows the context of a parent route and doesn't run parent's loader again.

wispy ferry
#

when you go sibling to sibling, their loaders run but the parent doesn't

#

when you go child to parent, the parent becomes the leaf route and runs

#

when you go parent to child, the child is now the leaf route and the parent isn't

wispy ferry
#

when you run useMatches(), you get a list of all matching nested routes. Only the last one in that array will revalidate

vernal sequoia
#

All right, this makes complete sense now. I see what you mean by leaf on route manifest vs the current url

#

But yeah, I guess it is fair to revalidate with this approach too

wispy ferry
#

only the "child-most" matching route

#

one day i'll find the right words for this

#

actually that's not even true, you can get multiple revalidating if you move from one branch to another

#
  • /users/id/comments/id might run 4 loaders
  • when navigating between comment IDs only the comment loader re-runs
  • when navigating to /products/id/pieces/id it's gonna run all those loaders
vernal sequoia
#

hahah. I guess you can say that whatever segment of the URL of the next route doesn't match the leafs (or the objects in the array of useMatches) gets their loaders run.
Even i am not able to put it into proper terms

#

But I get what you mean

wispy ferry
#

All new matching loaders + the child-most matching loader whether it's new or not

vernal sequoia
#

Yeah, got it

#

Thanks a bunch for this!! Really appreciate it

#

🙏🏽