#Load root loader's useLoaderData with fetcher.load?

1 messages · Page 1 of 1 (latest)

ionic sun
#

I'm loading user info and env variables in the root loader. Since categories don't change often I decided to load it in the root loader and get it with useMatches.

The problem is when I update categories, I want to refetch the categories in the root loader. I tried fetcher.load in a hope that it would update the userLoaderData but in this thread https://discord.com/channels/770287896669978684/1032572868724277268 @raw grove mentions that fetcher.load doesn't update the userLoaderData.

I don't want to refetch categories every time a modal is opened that's why I decided to fetch it in the root loader. Another option would be is to maintain a state and use it with context and after adding a new category update the state.

raw grove
#

Are you updating categories from the client here?

#

If you're updating category from client with Form action or fetcher.submit, it should revalidate all the loaders by default.

ionic sun
raw grove
#

Only remove unstable_shouldReload from your root loader?

#

Ideally, you should fix whatever that causes your loader to run so slow.

ionic sun
# raw grove Ideally, you should fix whatever that causes your loader to run so slow.

This was a different bug. I had a fetcher inside a modal and a global state responsible for showing this loading state.
As soon as I get response from the server I was closing the modal and because of that the fetcher was left hanging so fetchers from useFetchers never resolved to state of idle .
Current fix is. In the modal I need to wait for fetcher.state to be idle before automatically closing the modal.

I followed this blog by @gilded hawk https://sergiodxa.com/articles/use-nprogress-in-a-remix-app

Sergio Xalambrí

Remix's philosophy is to kill all the spinner! This is amazing, but sometimes it's not possible. Connections may be...