redirectionio / vercel-middleware

Vercel edge middleware for redirection.io
MIT License
0 stars 2 forks source link

Incompatible with Server actions ? #2

Closed tlenclos closed 3 weeks ago

tlenclos commented 2 months ago

While using with Next.js and server actions we encountered this issue

TypeError: A request with a one-time-use body (it was initialized from a stream, not a buffer) encountered a redirect requiring the body to be retransmitted. To avoid this error in the future, construct this request from a buffer-like body initializer.

Sadly this is not happening on preview environments. Here is the complete vercel logs for one POST request using server action

  {
    "TimeUTC": "2024-08-07 20:40:12",
    "timestampInMs": 1723063212684,
    "requestPath": "gruumo.fr/",
    "requestMethod": "POST",
    "responseStatusCode": -10,
    "requestId": "szd59-1723063212604-2f1b75c6ee1f",
    "requestUserAgent": [
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
    ],
    "level": "error",
    "environment": "production",
    "branch": "main",
    "vercelCache": "-",
    "type": "edge-middleware",
    "function": "/src/middleware",
    "host": "gruumo.fr",
    "deploymentDomain": "picksale-jdn8zawcy-premieroctet.vercel.app",
    "deploymentId": "dpl_GtpFkBUiGLSD1NEFT926VDV7p4i2",
    "lambdaDurationInMs": -1,
    "lambdaRegion": "-",
    "lambdaMaxMemoryUsed": -1,
    "lambdaMemorySize": -1,
    "message": "TypeError: A request with a one-time-use body (it was initialized from a stream, not a buffer) encountered a redirect requiring the body to be retransmitted. To avoid this error in the future, construct this request from a buffer-like body initializer.",
    "projectId": "prj_cr7XhVuM7pSBcCWaxqFZXU0cK6dg",
    "wafAction": "-"
  },
  {
    "TimeUTC": "2024-08-07 20:40:12",
    "timestampInMs": 1723063212655,
    "requestPath": "gruumo.fr/",
    "requestMethod": "POST",
    "responseStatusCode": -10,
    "requestId": "szd59-1723063212604-2f1b75c6ee1f",
    "requestUserAgent": [
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
    ],
    "level": "error",
    "environment": "production",
    "branch": "main",
    "vercelCache": "-",
    "type": "edge-middleware",
    "function": "/src/middleware",
    "host": "gruumo.fr",
    "deploymentDomain": "picksale-jdn8zawcy-premieroctet.vercel.app",
    "deploymentId": "dpl_GtpFkBUiGLSD1NEFT926VDV7p4i2",
    "lambdaDurationInMs": -1,
    "lambdaRegion": "-",
    "lambdaMaxMemoryUsed": -1,
    "lambdaMemorySize": -1,
    "message": "TypeError: A request with a one-time-use body (it was initialized from a stream, not a buffer) encountered a redirect requiring the body to be retransmitted. To avoid this error in the future, construct this request from a buffer-like body initializer.",
    "projectId": "prj_cr7XhVuM7pSBcCWaxqFZXU0cK6dg",
    "wafAction": "-"
  },
  {
    "TimeUTC": "2024-08-07 20:40:12",
    "timestampInMs": 1723063212642,
    "requestPath": "gruumo.fr/",
    "requestMethod": "POST",
    "responseStatusCode": -10,
    "requestId": "szd59-1723063212604-2f1b75c6ee1f",
    "requestUserAgent": [
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
    ],
    "level": "error",
    "environment": "production",
    "branch": "main",
    "vercelCache": "-",
    "type": "edge-middleware",
    "function": "/src/middleware",
    "host": "gruumo.fr",
    "deploymentDomain": "picksale-jdn8zawcy-premieroctet.vercel.app",
    "deploymentId": "dpl_GtpFkBUiGLSD1NEFT926VDV7p4i2",
    "lambdaDurationInMs": -1,
    "lambdaRegion": "-",
    "lambdaMaxMemoryUsed": -1,
    "lambdaMemorySize": -1,
    "message": "TypeError: A request with a one-time-use body (it was initialized from a stream, not a buffer) encountered a redirect requiring the body to be retransmitted. To avoid this error in the future, construct this request from a buffer-like body initializer.",
    "projectId": "prj_cr7XhVuM7pSBcCWaxqFZXU0cK6dg",
    "wafAction": "-"
  },
  {
    "TimeUTC": "2024-08-07 20:40:12",
    "timestampInMs": 1723063212642,
    "requestPath": "gruumo.fr/",
    "requestMethod": "POST",
    "responseStatusCode": -10,
    "requestId": "szd59-1723063212604-2f1b75c6ee1f",
    "requestUserAgent": [
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
    ],
    "level": "error",
    "environment": "production",
    "branch": "main",
    "vercelCache": "-",
    "type": "edge-middleware",
    "function": "/src/middleware",
    "host": "gruumo.fr",
    "deploymentDomain": "picksale-jdn8zawcy-premieroctet.vercel.app",
    "deploymentId": "dpl_GtpFkBUiGLSD1NEFT926VDV7p4i2",
    "lambdaDurationInMs": -1,
    "lambdaRegion": "-",
    "lambdaMaxMemoryUsed": -1,
    "lambdaMemorySize": -1,
    "message": "TypeError: A request with a one-time-use body (it was initialized from a stream, not a buffer) encountered a redirect requiring the body to be retransmitted. To avoid this error in the future, construct this request from a buffer-like body initializer.",
    "projectId": "prj_cr7XhVuM7pSBcCWaxqFZXU0cK6dg",
    "wafAction": "-"
  },
  {
    "TimeUTC": "2024-08-07 20:40:12",
    "timestampInMs": 1723063212606,
    "requestPath": "gruumo.fr/",
    "requestMethod": "POST",
    "responseStatusCode": 500,
    "requestId": "cdg1::szd59-1723063212604-2f1b75c6ee1f",
    "requestUserAgent": [
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
    ],
    "level": "error",
    "environment": "production",
    "branch": "main",
    "vercelCache": "-",
    "type": "edge-middleware",
    "function": "/src/middleware",
    "host": "gruumo.fr",
    "deploymentDomain": "picksale-jdn8zawcy-premieroctet.vercel.app",
    "deploymentId": "dpl_GtpFkBUiGLSD1NEFT926VDV7p4i2",
    "lambdaDurationInMs": -1,
    "lambdaRegion": "-",
    "lambdaMaxMemoryUsed": -1,
    "lambdaMemorySize": -1,
    "message": "[POST] [middleware: \"src/middleware\"] / reason=EDGE_FUNCTION_INVOCATION_FAILED, status=500, user_error=true",
    "projectId": "prj_cr7XhVuM7pSBcCWaxqFZXU0cK6dg",
    "wafAction": "-"
  },

Sadly we had to disable the integration due to this issue.

markomitranic commented 1 month ago

@tlenclos afaik this has been resolved a while ago. I'm using it in production with both server actions and tRPC without issues.

xavierlacot commented 3 weeks ago

Thanks for the report. It has indeed been fixed in 25b596a90540dd054d13b8d0f6105c50915cf608