-
Notifications
You must be signed in to change notification settings - Fork 367
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
refactor: [M3-8712] - Tanstack Reat Router rollout setup + betas routes migration #11049
Conversation
b95457c
to
abdd0cb
Compare
*/} | ||
<Route path="*"> | ||
<RouterProvider router={migrationRouter} /> | ||
</Route> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the primary deferring change described in the PR summary.
const { data: beta, isError, isLoading } = useBetaQuery(betaId); | ||
const navigate = useNavigate(); | ||
const { betaId } = useParams({ from: '/betas/signup/$betaId' }); | ||
const { data: beta, isError, isLoading } = useBetaQuery(betaId, !!betaId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using params rather than state seems to me like an always better pattern - i don't see any drawback of doing so, hopefully i did not miss anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought back when this was implemented #9544 (comment)
Should be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this migration we will see most feature/index.tsx
deleted since the routing is now centralized
useQuery({ | ||
...betaQueries.beta(id), | ||
enabled, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just adding the enabled
parameter since we now have a URL param to check if we want to run the query or not
return ( | ||
<React.Suspense fallback={<SuspenseLoader />}> | ||
<Outlet /> | ||
{selfServeBetas ? <Outlet /> : <NotFound />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving the <MainContent />
flag logic here, which is where it belongs now
@@ -8,5 +8,4 @@ export type RouterContext = { | |||
isACLPEnabled?: boolean; | |||
isDatabasesEnabled?: boolean; | |||
isPlacementGroupsEnabled?: boolean; | |||
selfServeBetas?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of the context anymore since we're check this at the betas root route now
}) | ||
); | ||
.filter((path) => path !== '/') | ||
.filter(Boolean); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just simplifying this util by using tanstack internals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice file cleanup 🧹
Coverage Report: ✅ |
cc786dd
to
2347dcf
Compare
433a136
to
01fb10a
Compare
cy.url().should('include', '/betas'); | ||
cy.url().should('not.include', 'signup'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdamore-linode! just wanted to mention you in here to take a quick look at the smoke test here. The feature's e2e coverage wasn't too exhaustive so that should add a lil' bit of confidence
@@ -53,6 +63,7 @@ describe('BetaDetails', () => { | |||
const errorBetasList = renderWithTheme( | |||
<BetaDetailsList | |||
betas={[]} | |||
dataQA="betas" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prop drilling a bit for testing purposes
<Typography>No betas found</Typography> | ||
)} | ||
</Stack> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, this was just an ugly loading experience. just a bit nicer with this update
}) | ||
); | ||
.filter((path) => path !== '/') | ||
.filter(Boolean); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice file cleanup 🧹
18004bd
to
b8b8a93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -70,6 +70,26 @@ export const router = createRouter({ | |||
declare module '@tanstack/react-router' { | |||
interface Register { | |||
// This infers the type of our router and registers it across the entire project | |||
router: typeof router; | |||
// router: typeof router; | |||
migrationRouter: MigrationRouter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is essentially making the router untyped / any.
I tried updating it restore the type-safety:
migrationRouter: MigrationRouter; | |
router: MigrationRouter; |
but this introduces many TypeScript errors because of all of the work we've done for routes that are not yet in the migrationRouter.
Any thoughts here? Will we just have to proceed with an untyped router until the end of this migration?
Maybe we could do something hacky like this, but it might cause us more trouble than we want
migrationRouter: MigrationRouter; | |
router: typeof router | MigrationRouter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnussman of course! 🤦 thx for catching.
So look at 75b20f0
I reintroduced the main router type for the applciation, which also forced me to cast AnyRouter
in a few places. Still much better! and allowed to get <Link />
to show path suggestion which is a good idea.
We still have good typing but will not narrow to the migrationRouter
routes which I was hoping to be able to do. We're half way there and get at least stronger rail guards and working suggestions 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Sounds good to me! 🚀
This reverts commit 65653a7.
75b20f0
to
e2f2ca8
Compare
Description 📝
This PR offers a safe pattern to be able to slowly roll out the new Tanstack routing migration.
The worry was to have to replace all of the routes and routing internals at once, resulting in a very large, hard to manage feature branch. Fortunately, this is not the case! The way we can incrementally implement the new routing is to accept to have the two routers cohabitating, and implement a cascading routing approach:
react-router-dom
:migrationRouter
(Tanstack)tanstack-react-router
<NotFound />
The deferring logic lives in
<MainContent />
where a wildcard catch-all will defer all unhandled routes to the tanstack<RouterProvider />
. The POC is showing that there's no conflict resulting in this approach.The
<Link />
components will be replaced last to avoid any potential conflict and keep things simple (already confirmed that the current behavior is not causing any problem navigating to the new routes 🎆Lastly, the PR introduces development tools to make out task easier and safer (linting, testing, inspecting)
Changes 🔄
betas/<detail>
How to test 🧪
Verification steps
As an Author I have considered 🤔
Check all that apply