cloudflare / cloudflare/templates

🐛 BUG: react-router + hono integration breaks key react-router features

Open
#434 0 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
2.1k
Forks
1k
Avg merge
17h 44m
Merged PRs (30d)
10

Description

### Which template does this pertain to?

react-router-postgres-ssr-template

### What versions are you using?

latest throughout (irrelevant)

### What operating system and version are you using?

WSL2 Ubuntu (irrelevant)

### Please provide a link to a minimal reproduction (optional)

_No response_

### Describe the Bug

In https://github.com/cloudflare/templates/blob/staging/react-router-postgres-ssr-template/api/index.js the following lines are an issue:

```js
// Handle React Router requests
app.get("*", async (c) => {
return requestHandler(c.req.raw, {
cloudflare: { env: c.env, ctx: c.executionCtx },
});
});

// Catch-all route for static assets
app.all("*", async (c) => {
return c.env.ASSETS.fetch(c.req.raw);
});
```

Using catch-all on `app.get('*')` only covers GET requests.

The entire point of react-router v7 in framework (SSR) mode is to _be_ remix v3.

Anyone who uses this template would not even be able to follow the official react-router which involves route actions and loaders to implement CRUD functionality.

Devs would hit unexpected 404's and the entire framework would generally not behave as expected.

This template could simply have react-router as the final catch all to hand over responsibility to that framework.

Some other ideas:

- is the assets catch all even necessary in that particular way?
- explicit catch-all assets behaviour could be implemented in react-router v7 route vs. at hono level
- more specific patterns could be used in hono for assets and/or react-router so that there are no conflicts

### Please provide any relevant error logs

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.