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

Bumps react-router-dom to v6 #2256

Merged
merged 37 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0280489
Bump React Router DOM to v6
infomiho Aug 27, 2024
0e712fc
e2e tests
infomiho Aug 27, 2024
6ac1c85
Update headless tests
infomiho Aug 27, 2024
5ef793d
Add routing headless test
infomiho Aug 27, 2024
8d6a544
Use hook for router. Use <Outlet /> for root component.
infomiho Aug 29, 2024
7e68b38
Merge branch 'main' into miho-react-router-dom-6
infomiho Sep 3, 2024
8b16709
Cleanup
infomiho Sep 3, 2024
b368838
Merge branch 'main' into miho-react-router-dom-6
infomiho Sep 4, 2024
dce8f8c
Fix headless tests
infomiho Sep 5, 2024
666f017
WIP optional static segments and splat paths
infomiho Sep 5, 2024
aa7f002
Update naming
infomiho Sep 5, 2024
f366600
Fixes example apps
infomiho Sep 5, 2024
da359a2
e2e tests
infomiho Sep 6, 2024
f29a976
Update types
infomiho Sep 6, 2024
177661c
Merge branch 'main' into miho-react-router-dom-6
infomiho Sep 9, 2024
fc541ab
Update docs
infomiho Sep 9, 2024
8584aa4
Update .build route helper
infomiho Sep 9, 2024
d2b9176
Update docs
infomiho Sep 10, 2024
9a429d0
Update root component docs
infomiho Sep 11, 2024
1bfef24
Set a default error boundry
infomiho Sep 11, 2024
5ce258c
Merge branch 'main' into miho-react-router-dom-6
infomiho Sep 11, 2024
c571ea7
Cleanup
infomiho Sep 12, 2024
e58aa7a
Updates todoApp unit tests
infomiho Sep 12, 2024
fcd805a
Bump to latest React Router patch version
infomiho Sep 23, 2024
bc4ae25
Update routes template
infomiho Sep 25, 2024
4a8f529
Update naming. Use * instead of splat as param name.
infomiho Sep 25, 2024
8aaa758
Formatting
infomiho Sep 25, 2024
ace73c9
Update comment
infomiho Sep 25, 2024
8031e5d
e2e tests
infomiho Sep 25, 2024
375d3aa
Update thoughts
infomiho Sep 25, 2024
19b2ca5
Handle root optional static segment. Improve naming.
infomiho Sep 25, 2024
126ad3f
Merge branch 'main' into miho-react-router-dom-6
infomiho Sep 26, 2024
f6d2d8d
Update package-lock.json for example apps
infomiho Sep 27, 2024
2314809
Merge branch 'main' into miho-react-router-dom-6
infomiho Sep 27, 2024
a23911c
Update docs
infomiho Sep 27, 2024
89abca1
Put Segment on multiple lines
infomiho Sep 27, 2024
c688966
Inline isSegmentOptional
infomiho Sep 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{={= =}=}}
import { useEffect, useRef, useState } from "react";
import { type AxiosResponse } from "axios";
import { Redirect, useLocation } from 'react-router-dom'
import { Navigate, useLocation } from 'react-router-dom'
import { useAuth } from 'wasp/client/auth'
import { api } from 'wasp/client/api'
import { initSession } from 'wasp/auth/helpers/user'
Expand All @@ -14,7 +14,7 @@ export function OAuthCallbackPage() {
const { error, user } = useOAuthCallbackHandler();

if (user !== undefined && user !== null) {
return <Redirect to="{= onAuthSucceededRedirectTo =}" />;
return <Navigate to="{= onAuthSucceededRedirectTo =}" replace />;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<Navigate /> replace <Redirect /> and the default behaviour changed, we need to add replace explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you got links to the changelog that prescribes this, you can include it into these comments.

I'm not sure is it worth spending the time, but it would help me better judge the change's validity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://reactrouter.com/en/main/upgrading/v5#use-usenavigate-instead-of-usehistory

If you prefer to use a declarative API for navigation (ala v5's Redirect component), v6 provides a Navigate component.

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{={= =}=}}
import React from 'react'

import { Redirect } from 'react-router-dom'
import { Navigate } from 'react-router-dom'
import { useAuth } from 'wasp/client/auth'

import { Loader } from '../../components/Loader'
Expand All @@ -17,7 +17,7 @@ const createAuthRequiredPage = (Page) => {
if (user) {
return <Page {...props} user={user} />
} else {
return <Redirect to="{= onAuthFailedRedirectTo =}" />
return <Navigate to="{= onAuthFailedRedirectTo =}" replace />
}
case 'loading':
return (
Expand Down
2 changes: 1 addition & 1 deletion waspc/data/Generator/templates/react-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import { QueryClientProvider } from '@tanstack/react-query'

import router from './router'
import { router } from './router'
import {
initializeQueryClient,
queryClientInitialized,
Expand Down
68 changes: 36 additions & 32 deletions waspc/data/Generator/templates/react-app/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{={= =}=}}
import React from 'react'
import { Route, Switch, BrowserRouter as Router } from 'react-router-dom'
import { useRoutes, BrowserRouter } from 'react-router-dom'
{=# rootComponent.isDefined =}
{=& rootComponent.importStatement =}
{=/ rootComponent.isDefined =}
Expand All @@ -25,35 +25,39 @@ export const routeNameToRouteComponent = {
{=/ routes =}
} as const;

const router = (
<Router basename="{= baseDir =}">
{=# rootComponent.isDefined =}
<{= rootComponent.importIdentifier =}>
{=/ rootComponent.isDefined =}
<Switch>
{=# isExternalAuthEnabled =}
{/*
Wasp specific routes *must* go first to prevent user
defined routes from overriding them.
Details in https://github.com/wasp-lang/wasp/issues/2029
*/}
<Route exact path="{= oAuthCallbackPath =}">
<OAuthCallbackPage />
</Route>
{=/ isExternalAuthEnabled =}
{Object.entries(routes).map(([routeKey, route]) => (
<Route
exact
key={routeKey}
path={route.to}
component={routeNameToRouteComponent[routeKey]}
/>
))}
</Switch>
{=# rootComponent.isDefined =}
</{= rootComponent.importIdentifier =}>
{=/ rootComponent.isDefined =}
</Router>
)
export function RouterRoutes() {
const routerRoutes = useRoutes([
{=# isExternalAuthEnabled =}
/*
Wasp specific routes *must* go first to prevent user
defined routes from overriding them.
Details in https://github.com/wasp-lang/wasp/issues/2029
*/
{
path: "{= oAuthCallbackPath =}",
element: <OAuthCallbackPage />
},
{=/ isExternalAuthEnabled =}
...(Object.entries(routes).map(([routeKey, route]) => {
const Component = routeNameToRouteComponent[routeKey]
return {
path: route.to,
element: <Component />
}
}))
])

return routerRoutes
}

export default router
export const router = (
<BrowserRouter basename="{= baseDir =}">
{=# rootComponent.isDefined =}
<{= rootComponent.importIdentifier =}>
{=/ rootComponent.isDefined =}
<RouterRoutes />
{=# rootComponent.isDefined =}
</{= rootComponent.importIdentifier =}>
{=/ rootComponent.isDefined =}
</BrowserRouter>
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as SocialIcons from '../social/SocialIcons'
import { SocialButton } from '../social/SocialButton'
{=/ isSocialAuthEnabled =}
{=# isAnyPasswordBasedAuthEnabled =}
import { useHistory } from 'react-router-dom'
import { useNavigate } from 'react-router-dom'
{=/ isAnyPasswordBasedAuthEnabled =}
{=# enabledProviders.isUsernameAndPasswordAuthEnabled =}
import { useUsernameAndPassword } from '../usernameAndPassword/useUsernameAndPassword'
Expand Down Expand Up @@ -147,7 +147,7 @@ export const LoginSignupForm = ({
const isLogin = state === 'login'
const cta = isLogin ? 'Log in' : 'Sign up';
{=# isAnyPasswordBasedAuthEnabled =}
const history = useHistory();
const navigate = useNavigate();
const onErrorHandler = (error) => {
setErrorMessage({ title: error.message, description: error.data?.data?.message })
};
Expand All @@ -159,7 +159,7 @@ export const LoginSignupForm = ({
isLogin,
onError: onErrorHandler,
onSuccess() {
history.push('{= onAuthSucceededRedirectTo =}')
navigate('{= onAuthSucceededRedirectTo =}')
},
});
{=/ enabledProviders.isUsernameAndPasswordAuthEnabled =}
Expand All @@ -172,7 +172,7 @@ export const LoginSignupForm = ({
setSuccessMessage(`You've signed up successfully! Check your email for the confirmation link.`)
},
onLoginSuccess() {
history.push('{= onAuthSucceededRedirectTo =}')
navigate('{= onAuthSucceededRedirectTo =}')
},
});
{=/ enabledProviders.isEmailAuthEnabled =}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading