react-router-hono-server 2.6.4 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -508,15 +508,23 @@ export interface HonoServerOptions<E extends Env = BlankEnv> extends Omit<HonoSe
508
508
 
509
509
  🚨 Redirecting from a middleware
510
510
  > [!IMPORTANT]
511
- > You **have to** use the `reactRouterRedirect` helper to redirect from a middleware.
511
+ > TLDR: If you encounter a `Error: Unable to decode turbo-stream response` after a redirect from your middleware, try to use `redirect` instead of `c.redirect`.
512
+ >
513
+ > `redirect` will use `c.redirect` for "normal" requests and a single-fetch-like response for React Router `.data` requests.
514
+ >
515
+ > If the next handler is a Hono middleware (ex: https://github.com/rphlmr/react-router-hono-server/discussions/56), you can use `c.redirect` as usual.
516
+ >
517
+ > You **have to** use the `redirect` helper to redirect from a middleware if the next handler that will receive this redirect is a React Router route.
512
518
  >
513
519
  > It returns a single-fetch-like response.
514
520
  >
515
521
  > If you use `c.redirect`, it will not work as expected and you will get a `Unable to decode turbo-stream response` error.
516
522
  >
517
523
  >```ts
518
- > import { reactRouterRedirect } from "react-router-hono-server/http";
524
+ > import { redirect } from "react-router-hono-server/http";
519
525
  >```
526
+ >
527
+ > I'm sorry for this inconvenience, I hope it can be "fixed" in future React Router versions.
520
528
 
521
529
  Middleware are functions that are called before React Router calls your loader/action.
522
530
 
package/dist/http.d.ts CHANGED
@@ -1,8 +1,24 @@
1
+ import { Context } from 'hono';
2
+
1
3
  /**
2
4
  * Redirect to a new location in a way that React Router can handle.
3
5
  *
4
6
  * It follows the Single Fetch Redirect protocol.
7
+ *
8
+ * @deprecated Use `redirect` instead. `import { reactRouterRedirect } from "react-router-hono-server/http"`
5
9
  */
6
10
  declare function reactRouterRedirect(location: string): Response;
11
+ /**
12
+ * Redirect to a new location.
13
+ *
14
+ * It follows the Single Fetch Redirect protocol, if the request path ends with `.data`.
15
+ */
16
+ declare function redirect(c: Context, location: string): Response;
17
+ /**
18
+ * Get the current request path
19
+ *
20
+ * If the path ends with `.data` (React Router Single Fetch query), it will be removed.
21
+ */
22
+ declare function getPath(c: Context): string;
7
23
 
8
- export { reactRouterRedirect };
24
+ export { getPath, reactRouterRedirect, redirect };
package/dist/http.js CHANGED
@@ -38,6 +38,17 @@ function reactRouterRedirect(location) {
38
38
  }
39
39
  );
40
40
  }
41
+ function redirect(c, location) {
42
+ if (c.req.path.includes(".data")) {
43
+ return reactRouterRedirect(location);
44
+ }
45
+ return c.redirect(location);
46
+ }
47
+ function getPath(c) {
48
+ return c.req.path.replace(".data", "");
49
+ }
41
50
  export {
42
- reactRouterRedirect
51
+ getPath,
52
+ reactRouterRedirect,
53
+ redirect
43
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-router-hono-server",
3
- "version": "2.6.4",
3
+ "version": "2.7.1",
4
4
  "type": "module",
5
5
  "description": "The Vite plugin you need to create a Hono server for your React Router app in less than 10 seconds.",
6
6
  "exports": {