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]: Cloudflare Pages - Outlet not working. #11480
Comments
When i just use npm run dev, so locally dev build it actually works, but when i run the build command to build the html, js etc it doesnt work anymore. |
Changed it to return (
<SnackbarProvider maxSnack={3} preventDuplicate>
<BrowserRouter>
<Routes>
{
ANDRoutes.map((route, index) => {
return <Route key={index} path={route.path} element={route.element} errorElement={<ErrorPage />} />
})
}
</Routes>
</BrowserRouter>
</SnackbarProvider>
) Now it works, but why not like before? |
+1 |
2 similar comments
+1 |
+1 |
+1 This was so frustrating to debug. There went my entire morning. 😥 Using Vite. import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom";
const newRouter = createBrowserRouter([
{
path: "/",
element: <Outlet />, // <-- Culprit!
children: [
{
index: true,
element: <div>Success!</div>, // <-- Removes this element in build
},
],
},
]);
export default function App() {
return <RouterProvider router={newRouter} />;
} |
I want to add the actuall Error you get when using the built app on production.
|
Not sure if related, but Outlet component is not working when built and on Vercel too with newest Vite (everything works when run with repo: https://github.com/danilo-89/react-error-boundary-research
|
+1 |
+1 same problem. It stopped working randomly with |
+1 when using Outlet for layout, i try remove it then build the routing logic work normaly without the layout |
+1 |
Same here. I have a build on Netlify fully working from over a month ago. Now the same build with all the exact same dependency versions breaks. So odd. |
I think this might have something to do with a recent update to Vite (or one of its transitive dependencies somewhere)? I created two projects — the only difference between them is one uses
Both will look fine at first because the |
+1. Actually nested didn't work for me at all after I built it, only in dev. The fix was un-nesting and passing {children}. |
i use the same fix (we broke the production without image backup) took us all day |
This might be due to rollup (or something else in the pipeline?) transforming function flattenRoutes<
RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject
>(
routes: RouteObjectType[],
branches: RouteBranch<RouteObjectType>[] = [],
parentsMeta: RouteMeta<RouteObjectType>[] = [],
parentPath = ""
): RouteBranch<RouteObjectType>[] {
...
} into function flattenRoutes(routes, branches, parentsMeta, parentPath) {
{
branches = [];
}
...
} and leading to no matched nested routes in every case. Maybe this is not even the same problem, but just in case, try reverting to older vite/rollup versions? |
I'm using Yarn, and a temp fix for that issue is: package.json: "resolutions": {
"rollup": "4.15.0"
} It seems to be this commit rollup/rollup#5443 |
I'm convinced this PR is causing the issue we are running into: rollup/rollup#5443 (comment) Definitely a compiler bug, not a React Router bug. |
you save my day |
I have the same issue with the Outlet the Bug appears after updating the react-router package, it took me all day to figure it out but finally, I solved the issue in my Code. the Code that isn't working for me : // ./src/App.jsx
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
{routes.map(({ element, path, id }) => (
<Route
key={id}
exact={true}
path={path}
element={createElement(element)}
/>
))}
<Route path="/*" element={<NotFound />} />
</Route>
</Routes>
</BrowserRouter>
) and i was using the // ./src/layout/index.jsx
return (
<Navbar />
<Outlet />
<Footer />
); i passed the // ./src/App.jsx
return (
<BrowserRouter>
<Layout>
<Routes>
<Route index element={<Home />} />
{routes.map(({ element, path, id }) => (
<Route
key={id}
exact={true}
path={path}
element={createElement(element)}
/>
))}
<Route path="/*" element={<NotFound />} />
</Routes>
</Layout>
</BrowserRouter>
) // ./src/layout/index.jsx
const Layout = ({children})=> {
return (
<Navbar />
{children}
<Footer />
);
} I think this is the same method NextJS is using in Layout also NOTE: This was a temporary solution but brophdawg11 soultion is more easier & effective |
I'm using Vite5, and a temp fix for that issue is: If you using npm, add to package.json file:
If you using pnpm, add to package.json file:
|
same here |
This is my code for Outlet and its also stop working on build but its working fine on dev server. can anyone please suggest me the solution that i am doing wrong ? it happens suddenly i didn't even changed anything |
@amentotech026 It's not necessarily your code, A recent change to the Rollup 4.16.1 breaks React Router on build. Just do what has been suggested above in your |
As noted above, this is a bug introduced in For now, you can install |
is a very serious problem🥲 |
I had a same issue. it makes me to waste full day to fix. :( not good. |
Rollup 4.16.2 is out with a fix that might address this. rollup/rollup#5482 (comment) |
This should be resolved in rollup 4.16.2: https://github.com/rollup/rollup/releases/tag/v4.16.2 |
No more need for overrides for Vite projects, now that rollup is updated, this fixes it:
|
Change the vite version to 4.4.1 build again and deploy. It should work |
|
What version of React Router are you using?
^6.22.3
Steps to Reproduce
I am using an normal createReactRouter, and since today it just doesnt work after i run the build command.
Expected Behavior
Using Routes, it just shows the 404 Error not found page, anything else is just a blank page,
I changed nothing on the Routing part or whatever, i just redeployed to cloudflare pages
Actual Behavior
Just blank page.
Main.ts
Routes.tsx
App.tsx
And home.tsx and the others returns valid Elements,
If i remove the Outlet and just use static my it displays that,
if i use use nothing appears just a blank white page, no errors nothing
The text was updated successfully, but these errors were encountered: