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

Works in CF Workers, doesn't in Miniflare #101

Closed
PH4NTOMiki opened this issue Nov 25, 2021 · 4 comments
Closed

Works in CF Workers, doesn't in Miniflare #101

PH4NTOMiki opened this issue Nov 25, 2021 · 4 comments
Labels
behaviour mismatch Different behaviour to Workers runtime fixed-in-next Fixed in next release

Comments

@PH4NTOMiki
Copy link

I'v been trying to use Remix(https://remix.run), and it uses Miniflare for dev server(if CF Workers chosen as output platform) and I have a code that works when deployed to CF Workers, , this is the code for the route:

export let action = async ({ request }) => {
  let formData = await request.formData();
  let answer = formData.get("answer");

  // Typical action workflows start with validating the form data that just came
  // over the network. Clientside validation is fine, but you definitely need it
  // server side.  If there's a problem, return the the data and the component
  // can render it.
  if (typeof answer !== "string") {
    return json("Come on, at least try!", { status: 400 });
  }

  if (answer !== "egg") {
    return json(`Sorry, ${answer} is not right.`, { status: 400 });
  }

  // Finally, if the data is valid, you'll typically write to a database or send or
  // email or log the user in, etc. It's recommended to redirect after a
  // successful action, even if it's to the same place so that non-JavaScript workflows
  // from the browser doesn't repost the data if the user clicks back.
  return redirect("/demos/correct");
};

but in dev server I get this in terminal

[mf:err] POST /demos/actions?_data=routes%2Fdemos%2Factions: TypeError: Response with null body status cannot have body
    at new Response (/home/mutic/dev/my-remix-app/node_modules/undici/lib/fetch/response.js:160:15)
    at new Response (file:///home/mutic/dev/my-remix-app/node_modules/@miniflare/core/src/standards/http.ts:393:13)
    at Object.construct (file:///home/mutic/dev/my-remix-app/node_modules/@miniflare/core/src/plugins/core.ts:62:29)
    at handleDataRequest (/home/mutic/dev/my-remix-app/node_modules/@remix-run/server-runtime/server.js:170:12)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at /home/mutic/dev/my-remix-app/node_modules/@remix-run/server-runtime/server.js:66:20
    at handleEvent (/home/mutic/dev/my-remix-app/node_modules/@remix-run/cloudflare-workers/worker.js:93:18)
    at EventTarget.[kDispatchFetch] (file:///home/mutic/dev/my-remix-app/node_modules/@miniflare/core/src/standards/event.ts:356:13)
    at Server.<anonymous> (file:///home/mutic/dev/my-remix-app/node_modules/@miniflare/http-server/src/index.ts:165:20)
POST /demos/actions?_data=routes%2Fdemos%2Factions 500 Internal Server Error (145.70ms)
@RossJHagan
Copy link

RossJHagan commented Nov 26, 2021

Some context as I ran into this issue and did some digging.

The creation of the Response in remix's server-runtime is using an empty string instead of null in a response with status code 204. As the behaviour in undici is to require a null body on a 204, it blows up.

Changing the server-runtime behaviour to create a response with null instead of "" in node_modules/@remix-run/server-runtime/server.js on line 170 corrects the behaviour. So looks like it may not be a miniflare issue.

Edit: see also: remix-run/remix#553

@rjgux
Copy link

rjgux commented Nov 26, 2021

Having a similar issue. Noticed a PR is open here remix-run/remix#547

@PH4NTOMiki
Copy link
Author

Yeah, thanks @RossJHagan you're right, but still it works in CF Workers, so it should in the dev environment as well, since the Cloudflare policy is that they will never break a code that works in production, source: https://blog.cloudflare.com/backwards-compatibility-in-cloudflare-workers/ so it should work in Miniflare as well, and it should get fixed in Remix as well.

@mrbbot mrbbot added the behaviour mismatch Different behaviour to Workers runtime label Nov 30, 2021
mrbbot added a commit that referenced this issue Dec 2, 2021
@mrbbot mrbbot added the fixed-in-next Fixed in next release label Dec 2, 2021
@mrbbot
Copy link
Contributor

mrbbot commented Dec 8, 2021

Hey! 👋 miniflare@2.0.0-rc.3 has just been released, including the fix for this. You can find the changelog here.

@mrbbot mrbbot closed this as completed Dec 8, 2021
mrbbot added a commit that referenced this issue Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behaviour mismatch Different behaviour to Workers runtime fixed-in-next Fixed in next release
Projects
None yet
Development

No branches or pull requests

4 participants