Skip to content

React Router 7#2866

Merged
balazsbajorics merged 102 commits intomainfrom
spike-7
May 20, 2025
Merged

React Router 7#2866
balazsbajorics merged 102 commits intomainfrom
spike-7

Conversation

@balazsbajorics
Copy link
Copy Markdown
Contributor

@balazsbajorics balazsbajorics commented Apr 16, 2025

If you want to try upgrading your Hydrogen Project to React Router 7:

  1. Make sure you are on Hydrogen 2025.1.4 with all Remix Future Flags turned on! Make sure your storefront runs fine and commit all changes before proceeding.
    Follow this guide if you haven’t turned on your future flags yet: Hydrogen future flag migration for React Router 7

  2. Run npx codemod remix/2/react-router/upgrade – don't worry, after the codemod your project will not be ready yet, we have a few more steps to do:

  3. Add react-router.config.ts file with these contents:

import type {Config} from '@react-router/dev/config';

export default {
  appDirectory: 'app',
  buildDirectory: 'dist',
  ssr: true,
} satisfies Config;
  1. In vite.config.ts delete all parameters of the reactRouter() plugin. These are just leftovers that the codemod did not clean up.
// if you have declared this type augmentation, delete it
- declare module '@remix-run/server-runtime' {
-   interface Future {
-     v3_singleFetch: true;
-   }
- }

...
export default defineConfig({
  plugins: [
    tailwindcss(),
    hydrogen(),
    oxygen(),
-    reactRouter({
-      presets: [hydrogen.v3preset()],
-      future: {
-        v3_fetcherPersist: true,
-        v3_relativeSplatPath: true,
-        v3_throwAbortReason: true,
-        v3_lazyRouteDiscovery: true,
-        v3_routeConfig: true,
-        v3_singleFetch: true,
-      },
-    }),
+   reactRouter(),
    tsconfigPaths(),
  ],
...
  1. Update the hydrogen dependencies to the 0.0.0-snapshot-20250520122031 version
rm -r node_modules
rm package-lock.json

npm install https://registry.npmjs.org/@shopify/cli-hydrogen/-/cli-hydrogen-0.0.0-snapshot-20250520122031.tgz https://registry.npmjs.org/@shopify/hydrogen/-/hydrogen-0.0.0-snapshot-20250520122031.tgz https://registry.npmjs.org/@shopify/remix-oxygen/-/remix-oxygen-0.0.0-snapshot-20250520122031.tgz
  1. Change env.d.ts: the declare module should be aimed at react-router and you have to add LoaderFunctionArgs and ActionFunctionArgs (reference file here)
...
- declare module '@shopify/remix-oxygen' {
+ declare module 'react-router' {
...
+  // TODO: remove this once we've migrated to `Route.LoaderArgs` for our loaders
+  interface LoaderFunctionArgs {
+    context: AppLoadContext;
+  }
+
+  // TODO: remove this once we've migrated to `Route.ActionArgs` for our actions
+  interface ActionFunctionArgs {
+    context: AppLoadContext;
+  }
...
}
  1. Change tsconfig.json: add ".react-router/types/**/*" to include, and add "rootDirs": [".", "./.react-router/types"] reference file HERE
{
  "include": [
    "./**/*.d.ts",
    "./**/*.ts",
    "./**/*.tsx",
+    ".react-router/types/**/*"
  ],
  "compilerOptions": {
+    "rootDirs": [".", "./.react-router/types"],
    "lib": [
...
  1. Add .react-router to the .gitignore file

  2. Now try running npm run codegen and npm run typecheck and npm run dev!

@shopify
Copy link
Copy Markdown
Contributor

shopify bot commented Apr 16, 2025

Oxygen deployed a preview of your spike-7 branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment April 16, 2025 9:14 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment May 20, 2025 3:20 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment May 20, 2025 3:20 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment May 20, 2025 3:20 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment May 20, 2025 3:20 PM

Learn more about Hydrogen's GitHub integration.

@balazsbajorics
Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions
Copy link
Copy Markdown
Contributor

🫰✨ Thanks @balazsbajorics! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20250519200352",
"@shopify/hydrogen": "0.0.0-snapshot-20250519200352",
"@shopify/remix-oxygen": "0.0.0-snapshot-20250519200352"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

@balazsbajorics balazsbajorics marked this pull request as ready for review May 19, 2025 20:17
@balazsbajorics
Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions
Copy link
Copy Markdown
Contributor

🫰✨ Thanks @balazsbajorics! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20250520122031",
"@shopify/hydrogen": "0.0.0-snapshot-20250520122031",
"@shopify/remix-oxygen": "0.0.0-snapshot-20250520122031"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

/.mf
.env
.shopify
.react-router
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

note to self: have a cursor rule telling the AI that this is now a react-router project, and not a @remix-run/react project.

Copy link
Copy Markdown

@brookslybrand brookslybrand left a comment

Choose a reason for hiding this comment

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

🎉

@balazsbajorics balazsbajorics merged commit e9132d8 into main May 20, 2025
11 checks passed
@balazsbajorics balazsbajorics deleted the spike-7 branch May 20, 2025 15:32
@ruggishop ruggishop mentioned this pull request May 21, 2025
5 tasks
@michael-land
Copy link
Copy Markdown
Contributor

"Follow this document" Why isn’t the migration document publicly accessible if we’re supposed to follow it?

@balazsbajorics

CleanShot 2025-05-22 at 14 42 49@2x

@rbshop
Copy link
Copy Markdown
Contributor

rbshop commented May 22, 2025

@michael-land apologies for that, we have since turned that document into a blog post that has been published. I've updated the link to point to https://hydrogen.shopify.dev/update/how-to-adopt-all-future-flags

juanpprieto pushed a commit that referenced this pull request Sep 17, 2025
* checkpoint: hydrogen lib is pulling in RR7 and types are fixed

* Update plugin.ts

* Update vite.config.ts

* gitignore and eslint ignore changes

* checkpoint: the skeleton is semi-updated, typecheck runs, npm run dev fails

* stripping sharedOptions.remixConfig from the hydrogen vite plugin

* updating remix-oxygen

* remove the classic compiler option from hydrogen-cli

* removing the classic remix example

* removing the classic-remix example leftovers

* checkpoint: CLI builds but the tests fail

* fix json syntax error in skeleton tsconfig.json

* changing all examples package jsons to match the skeleton

* fixing typo

* fixing two false detections of classic projects

* removing @remix-run/fs-routes from root package.json

* do I need react-router-dom in the skeleton too?

* pruning remix-config.ts in cli

* fixing tsconfig of cli

* fixing types of hydrogen Pagination.ts

* pruning exports from remix-oxygen/index.ts – note: all of these re-exports should be removed

* removing outdated reference to @remix-run/server-runtime here

* removing no-longer applicable remix-run reference

* type fix in hydrogen / VariantSelector.ts

* Update package-lock.json

* updating ALL of the examples to React Router 7 via codemod

* Update entry.server.tsx

* it seems like the skeleton's build directory should be 'dist' according to CLI tests

* _temporarily_ adding react-router-dom to the root package. this should be weeded out

* respect HYDROGEN_DISABLE_VIRTUAL_ROUTES in hydrogenRoutes

* prettier change

* the auto-upgrade now ALSO works with react router

* fixing build

* CLI: temporarily skipping typecheck test

* Update collections.$handle.tsx

* fixing botched merge

* running Prettier on package.json

* adding this vite config v6 fix, just in case... but maybe we will remove this

* oh god

* a few more remix-runs

* Update Footer.tsx

* codegen now runs react-router typegen

* removing react-router typegen from the typecheck command

* Update package.json

* fixing types in examples/express

* skeleton env.d.ts refers to react-router now

* fixing skeleton type errors

* fixing examples/express/env.d.ts

* fixing all the env.d.ts 'es

* adding these env.d.ts es to fix the remaining example tsc failures

* Update package-lock.json

* Snapit: adding @shopify/remix-oxygen to the forced changeset

* adding back three re-exported types from react-router

* Update codegen.ts

* adding .react-router to the skeleton gitignore

* undo root .gitignore changes

* react-router codegen supports watch flag now

* reformatting codegen.ts

* TODO BEFORE MERGE remove ALL references to legacy-runtime

* fixing a few react-router imports

* const REMIX_COMPILER_ERROR_MESSAGE

* removing react-router and react-router-dom from the root dependencies

* regenerated package-lock.json from the main baseline

* Revert "regenerated package-lock.json from the main baseline"

This reverts commit e5b074f.

* Revert "removing react-router and react-router-dom from the root dependencies"

This reverts commit 28fc65e.

* pinning react-router to 7.6.0

* adding a changeset

* adding cursor rule with hydrogen upgrade instructions

* Update package-lock.json

* simplifying skeleton's virtual import

* Update thick-tigers-grab.md

* removing all references to legacy-runtime

* Update dev.env.d.ts

* Update env.d.ts

* scrubbing more references to legacyRuntime

* whooops

* re-enabling createContentSecurityPolicy example

* try removing the HYDROGEN_DISABLE_VIRTUAL_ROUTES fix

* will this test pass now, maybe?

* removing two TODO BEFORE MERGEs as they are done!

* removing remix-oxygen/src/implementations.ts

* what happens if we only change the relevant parts in the vite.config.ts?

* Delete upgrade-hydrogen-react-router-7-2025.5.0.mdc

* Major version bumping libraries that now depend on react-router@7

* renaming remixBuild to reactRouterBuild
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants