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

[Bug]: Component causing incorrect re-renders #10283

Closed
brophdawg11 opened this issue Mar 29, 2023 · 6 comments · Fixed by #10287
Closed

[Bug]: Component causing incorrect re-renders #10283

brophdawg11 opened this issue Mar 29, 2023 · 6 comments · Fixed by #10287
Labels

Comments

@brophdawg11
Copy link
Contributor

brophdawg11 commented Mar 29, 2023

What version of React Router are you using?

6.9.0

Steps to Reproduce

Original Discord thread

let router = createBrowserRouter([
  {
    path: "/",
    Component: Layout,
    children: [
      {
        index: true,
        Component: Index,
      },
      {
        path: "a",
        Component: A,
      },
    ],
  },
]);

export default function App() {
  return <RouterProvider router={router} />;
}

function Layout() {
  console.log("rendering Layout");
  return (
    <>
      <Link to="/">Home</Link>&nbsp;&nbsp;
      <Link to="a">A</Link>&nbsp;&nbsp;
      <Outlet />
    </>
  );
}

function Index() {
  console.log("rendering Index");
  return <h1>Index</h1>;
}

function A() {
  console.log("rendering A");
  return <h1>A</h1>;
}

Expected Behavior

Component shouldn't cause additional re-renders compared to element

Actual Behavior

Component causes additional re-renders because React.createElement is re-called each time

@brophdawg11 brophdawg11 self-assigned this Mar 29, 2023
@brophdawg11
Copy link
Contributor Author

Current workaround is to use Component: React.memo(Layout)

@MichaelDeBoey
Copy link
Member

Fixed by #10287

@brophdawg11
Copy link
Contributor Author

Reopening until this is released to npm

@brophdawg11 brophdawg11 reopened this Apr 17, 2023
@brophdawg11
Copy link
Contributor Author

brophdawg11 commented Apr 21, 2023

Aligning with Remix here - will close this issue with awaiting release. This will be available when React Router 6.11 is released.

@brophdawg11 brophdawg11 removed their assignment Apr 21, 2023
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 6.11.0-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 6.11.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11 brophdawg11 removed the awaiting release This issue have been fixed and will be released soon label Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants