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

Uncaught clientLoader errors in React 18 (specific to presence of useEffect adding/removing script in the root.tsx layout export) #13106

Open
smoooty opened this issue Feb 25, 2025 · 0 comments
Labels

Comments

@smoooty
Copy link

smoooty commented Feb 25, 2025

I'm using React Router as a...

framework

Reproduction

reproduction: https://stackblitz.com/edit/github-4zctv3wf?file=app%2Froot.tsx

I've run into an odd issue using react-router framework mode with react 18 (I also noticed the issue does not seem to be present in 19). If I have the following component in my root.tsx Layout export,

function TestScript() {
  useEffect(() => {
    const script = document.createElement("script");
    document.head.appendChild(script)
    return () => {
      if (script) {
        document.head.removeChild(script);
      }
    }
  }, []);
  return null;
};

And then a clientLoader throws an error, rather than displaying the root ErrorBoundary, I cycle through error messages in the browser console and the app becomes unresponsive.

demo_rr.mov

System Info

System:
  OS: Linux 5.0 undefined
  CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 0 Bytes / 0 Bytes
  Shell: 1.0 - /bin/jsh
Binaries:
  Node: 18.20.3 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 10.2.3 - /usr/local/bin/npm
  pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
  @react-router/dev: * => 7.2.0 
  @react-router/node: * => 7.2.0 
  @react-router/serve: * => 7.2.0 
  react-router: * => 7.2.0 
  vite: ^6.0.11 => 6.1.1

Used Package Manager

npm

Expected Behavior

When an Error occurs in the clientLoader, the Error should be caught by the root.tsx ErrorBoundary and display the ErrorBoundary jsx.

Actual Behavior

When an Error occurs in the clientLoader, a loop of errors prints in the console and the application becomes unresponsive.

@smoooty smoooty added the bug label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant