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

POC: react router migration compatibility mode setup #2929

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sarah4VT
Copy link
Contributor

@Sarah4VT Sarah4VT commented Sep 26, 2024

Summary

This is a very small POC to see how the react-router-dom-v5-compat package works and if it would be a good fit for us to leverage as we migrate from react-router v5 -> v6. It was mentioned at the very top of the official React-Router migration from v5 docs, and I didn't see it discussed (good or bad) in the RFC, so I assumed if it had been considered and rejected already, that would have been documented in the RFC.

It seems to allow us to use the new v6 API's at the same time we use v5 features which allows for a gradual migration without breakages.

Description

The first commit sets up the package.

The second commit shows examples of a file fully migrated to using v6 only features. It also includes a file that demonstrates mixed v5 and v6 features in a single file.

Other notes

I tried to do this POC on app kit which probably has more interesting routes, but it's been a minute since I've worked in that project and I couldn't get it running and it was past Europe time zone to get chapter help. So I decided to try it in UI kit at least, but it's hard for me to test as I think these files are the Percy visual test files? I was going to open a PR anyways for people to review the code that was required to do this, but I'm watching to see if the visual tests pass, because I've never run these locally as I don't have the access to update them anyways.

@Sarah4VT Sarah4VT added 🚧 Status: WIP Work in progress fe-chapter-rotation Tasks coming from frontend chapter work labels Sep 26, 2024
@Sarah4VT Sarah4VT self-assigned this Sep 26, 2024
Copy link

changeset-bot bot commented Sep 26, 2024

⚠️ No Changeset found

Latest commit: 8979e5e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Sep 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 26, 2024 8:01pm

@@ -83,7 +83,7 @@ const renderIcon = (iconName, color, size) => {
};

export const component = () => (
<Switch>
<Routes>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a full switch over to the v6 API. This was a straightforward route that I didn't see anything else that needed to be migrated, but let me know if I missed anything. Hard to test as I think these are the Percy screenshot tests that I don't have access to run?

Copy link
Contributor Author

@Sarah4VT Sarah4VT Sep 26, 2024

Choose a reason for hiding this comment

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

Example of a file with mixed v5 and v6 API's being used.

Switch your Route to a CompatRoute and then you can use v5 or v6 API. You can see the Routes that specified component (v5) I switched to element (v6), however on the last Route, using render is a v5 API only and needs to be converted to element as well. I left it in to demo both API's running at once in a single file.

)}
/>
{allSortedComponents.map((Component) => (
<CompatRouter>
Copy link
Contributor Author

@Sarah4VT Sarah4VT Sep 26, 2024

Choose a reason for hiding this comment

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

Other than installing the package, adding the CompatRouter is the only setup that needs to happen to be able to use both v5 and v6 API's.

The rest of the line changes are just indention.

@Sarah4VT Sarah4VT requested review from emmenko and a team September 26, 2024 20:08
@CarlosCortizasCT
Copy link
Contributor

Hi @Sarah4VT

The changes you are making here can be tested locally by running the Visual Testing App which is the one also used for the Percy integration.
You just need to build the packages and then start the app by running this commands:

# Build packages
yarn build

# Start app
yarn visual-testing-app:start

You can then access the application in http://localhost:3000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fe-chapter-rotation Tasks coming from frontend chapter work 🚧 Status: WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants