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

Add react-router v7 example #752

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

matthewlynch
Copy link
Collaborator

@matthewlynch matthewlynch commented Dec 22, 2024

This PR adds a react-router recipe for Puck.

Note: I had to bump the node version to 22 because some of the RR7 deps required a minimum version of 20 and that caused issues with some of the next js apps.

Copy link

vercel bot commented Dec 22, 2024

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

Name Status Preview Comments Updated (UTC)
puck-demo ❌ Failed (Inspect) Dec 28, 2024 2:44pm
puck-docs ❌ Failed (Inspect) Dec 28, 2024 2:44pm

@matthewlynch
Copy link
Collaborator Author

@chrisvxd deps are failing to install because we need to bump the minimum engine version for node:

error @react-router/[email protected]: The engine "node" is incompatible with this module. Expected version ">=20.0.0". Got "18.20.5"

Copy link
Member

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Awesome thanks @matthewlynch! Left some comments 🙃

@@ -19,7 +19,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
Copy link
Member

Choose a reason for hiding this comment

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

This bump is causing CI to fail for Vercel. Noted your comment on RR7 dependencies, though. Need to probe this a bit further.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could replicate the issue locally, moving to v22 (LTS) works so will try on CI once I've sorted a monorepo issue.

recipes/react-router/app/routes/puck-splat.tsx Outdated Show resolved Hide resolved

import "@measured/puck/puck.css";

import type { Route } from "./+types/puck-splat";
Copy link
Member

Choose a reason for hiding this comment

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

What is this + import magic?!

Copy link
Collaborator Author

@matthewlynch matthewlynch Dec 28, 2024

Choose a reason for hiding this comment

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

This is something new in RR7. Types are auto generated based on file changes for the route. Works really well. See https://reactrouter.com/how-to/route-module-type-safety.

recipes/react-router/app/root.tsx Outdated Show resolved Hide resolved
recipes/react-router/app/puck.config.tsx Outdated Show resolved Hide resolved
@@ -0,0 +1,13 @@
export function resolvePuckPath(path: string = "") {
const url = new URL(path, "https://placeholder.com/");
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear that placeholder.com doesn't need to be changed by the user (in fact, I thought I would have to change it after generating).

I understand the technique here, but is there a cleaner way we could do this without requiring the placeholder string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a comment saying it isn't important and set the origin as a default parameter value. Let me know if you want to change it to something else.

recipes/react-router/tailwind.config.ts Outdated Show resolved Hide resolved
"@measured/puck": "^0.17.1",
"@react-router/node": "^7.0.2",
"@react-router/serve": "^7.0.2",
"isbot": "^5.1.17",
Copy link
Member

Choose a reason for hiding this comment

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

Noticed this is in the standard react-router template, but is this dep necessary?

Copy link
Collaborator Author

@matthewlynch matthewlynch Dec 28, 2024

Choose a reason for hiding this comment

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

Defaults from the base RR template, it can be removed but we'd need to add a new server entry file because RR expects the dependency to be there. I think it should be kept based on: https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation.

Let me know what you think? For now, I've run react-router reveal which generates the default files that is being used.

recipes/react-router/README.md Outdated Show resolved Hide resolved
recipes/react-router/README.md Show resolved Hide resolved
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.

2 participants