Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect in child action doesn't refresh parent loader #8783

Closed
TheBuilderJR opened this issue Feb 18, 2024 · 4 comments
Closed

redirect in child action doesn't refresh parent loader #8783

TheBuilderJR opened this issue Feb 18, 2024 · 4 comments

Comments

@TheBuilderJR
Copy link

Reproduction

I have an action in some leaf route

app/routes/team.$team.$workspace.$query.$index.tsx

export const action = async ({ request, context }: any) => {
  // ...
  return redirect(`/team/${teamSlug}/${workspaceSlug}/${querySlug}`);
}

And the action is being submitted via a useFetcher

    fetcher.submit(
      {
        sql,
        team,
        workspace,
        query,
        index,
      },
      { method: "post" }
    );

And the child route correctly reloads all data, but the parent route's loader in app/routes/team.$team.tsx doesn't.

Is this expected? It feels like all loaders should be reloaded on mutation events.

System Info

System:
    OS: macOS 14.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 119.60 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
    pnpm: 8.15.1 - ~/Library/pnpm/pnpm
  Browsers:
    Brave Browser: 113.1.51.110
    Chrome: 121.0.6167.184
    Safari: 17.3.1
  npmPackages:
    @remix-run/cloudflare: ^2.5.1 => 2.6.0 
    @remix-run/cloudflare-pages: ^2.5.1 => 2.6.0 
    @remix-run/css-bundle: ^2.5.1 => 2.6.0 
    @remix-run/dev: ^2.5.1 => 2.6.0 
    @remix-run/react: ^2.5.1 => 2.6.0

Used Package Manager

npm

Expected Behavior

All loaders to refresh

Actual Behavior

only child loaders are refreshed

@TheBuilderJR TheBuilderJR changed the title redirect in action doesn't refresh parent loader redirect in child action doesn't refresh parent loader Feb 18, 2024
@kiliman
Copy link
Collaborator

kiliman commented Feb 18, 2024

What does the Network tab look like?

@TheBuilderJR
Copy link
Author

TheBuilderJR commented Feb 18, 2024

Here's a video. Notice how only after a manual refresh does the left bar reload the data.

Area.mp4

@TheBuilderJR
Copy link
Author

This actually seems to be a problem with react arborist. Closing this issue since it's not remix related.

@dusty
Copy link

dusty commented Mar 8, 2024

Just thought I'd add a comment on here in case anyone searches. I was having a similar problem where it seemed my action wasn't reloading the parent loader.

Turns out my page had a cancel button (which was a link) on it with a prefetch set to intent. I also set some cache headers on prefetch.

import { isPrefetch } from 'remix-utils/is-prefetch'
...
const isGet = request.method.toLowerCase() === 'get'
if (isGet && isPrefetch(request) && !headers.has('cache-control')) {
  headers.set('cache-control', 'private, max-age=5, stale-while-revalidate=10')
}

So, I happened to be hovering the cancel button before I got to the submit button. This was sending a prefetch that was cached by the time I hit the submit button and redirected.

I was able to figure that out by looking at the network tab and seeing that the parent loader was actually being served by a prefetch cache. Removing the intent fixed the problem.

footgun

:)

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

No branches or pull requests

3 participants