Skip to content

Infinite loop when using fetcher.load in latest Remix releases #6072

@BrycePearce

Description

@BrycePearce

What version of Remix are you using?

1.14.0 (also on 1.15)

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

1.) Create a resource-route (or any loader) that returns anything. In this case I'm returning json({hello: 'world'})
2.) In any route, create a state variable to track to see if it has been invoked. For example

  let fetcher = useFetcher();
  const [shouldCallResourceRoute, setShouldCallResourceRoute] = useState(true);

  useEffect(() => {
    if (shouldCallResourceRoute) {
      setShouldCallResourceRoute(false); // this should cause this fetcher to never load again. But it infinite loops
      fetcher.load("/resource-routes/resource");
    }
  }, [fetcher, shouldCallResourceRoute]);

3.) Note the infinite loop / crash that happens
image

-Note-

I am upgrading my Remix from an earlier version where my existing code worked fine. This bug only appeared after upgrading and I was able to replicate in a code sandbox here:

https://codesandbox.io/p/sandbox/hopeful-night-z2lsum?file=%2Fapp%2Froutes%2Findex.tsx&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A7%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A7%7D%5D

Expected Behavior

The fetcher should only load once

Actual Behavior

An infinite loop occurs, crashing the page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions