mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
15.97k stars 519 forks source link

All request headers are missing (remix on lambda) #2278

Closed KnisterPeter closed 2 months ago

KnisterPeter commented 2 months ago

Prerequisites

Environment check

Node.js version

20.x (lambda)

Reproduction repository

-

Reproduction steps

It's not easy to describe and to reproduce. I'll open an issue nonetheless (you might decide to close it).

  1. Create a remix app
  2. Bundle it for AWS lambda (locally everything seems fine)
  3. Log the request headers outside of remix (in the lambda handler)
  4. Log the request headers inside of remix (e.g. in a header)

It's only happening with MSW enabled.

Current behavior

There are all headers available in the lambda request object. There are NO headers available in the remix web Request.

Expected behavior

The headers should be kept on the request object.

KnisterPeter commented 2 months ago

Maybe related to this one https://github.com/mswjs/msw/issues/2269?

KnisterPeter commented 2 months ago

Additionally it does work as expected with msw 2.2.3 (maybe also newer version). I can try to identify the latest working version.

kettanaito commented 2 months ago

Hi, @KnisterPeter. Are there any errors during this? Really hard to see what's wrong without any reproduction or a stack trace. Otherwise, indeed sounds similar to #2269.

KnisterPeter commented 2 months ago

Thanks for asking, @kettanaito. No errors, no logs, just the missing headers. It's hard to debug, took me a while to identify msw for this. I can try to create a reproducable repo, but it's lambda only for us. I couldn't recreate the issue locally so far.

kettanaito commented 2 months ago

I'm releasing https://github.com/mswjs/interceptors/pull/639, which may be related to your issue. But it wouldn't have caused headers to be missing, so yours may be something else.

A reproduction repository would be best! Don't focus on Lambda etc, just create an empty Remix app, try to reproduce what you are doing to the minimum. Use Examples for quick reference, we've got a Remix example you can fork and modify.

Looking forward to investigating this one once there's a reproduction repo!

KnisterPeter commented 2 months ago

@kettanaito I'm still trying to create a reproducer but failed so far. The change which introduced the error for us did happen in this commit (https://github.com/mswjs/msw/commit/f5785bfba1a026075feca4f74cadfcb636ffc257). I guess it's somewhere in the bigger jump of the @mswjs/interceptors update (0.29 -> 0.35). I'll continue to investigate that.

KnisterPeter commented 2 months ago

Interestingly I can update the interceptors package to the latest version, if I keep msw at version 2.4.3 everything is fine. I have no idea what are the changes which lead to the issue. You stated in the merged PR that the bump is quite significant: https://github.com/mswjs/msw/pull/2268

KnisterPeter commented 2 months ago

Also this seems to be related: https://github.com/mswjs/msw/issues/2269#issuecomment-2354283669

KnisterPeter commented 2 months ago

While debugging and trying to create a reproducer I've stumbled across these errors:

TypeError: Cannot read properties of undefined (reading 'length')
    at recordRawHeader (./node_modules/.pnpm/@mswjs+interceptors@0.35.6/node_modules/@mswjs/interceptors/lib/node/chunk-RWGRRMVU.mjs:118:33)
    at Object.apply (./node_modules/.pnpm/@mswjs+interceptors@0.35.6/node_modules/@mswjs/interceptors/lib/node/chunk-RWGRRMVU.mjs:188:7)
    at compress2 (./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/middleware/compress/index.js:21:21)
    at async dispatch (./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/compose.js:29:17)
    at async dispatch (./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/compose.js:29:17)
    at async ./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/hono-base.js:200:25
    at async responseViaResponseObject (./node_modules/.pnpm/@hono+node-server@1.13.0_hono@4.6.1/node_modules/@hono/node-server/dist/index.mjs:339:13)
TypeError: Cannot set property headers of #<_Response> which has only a getter
    at Object.construct (./node_modules/.pnpm/@mswjs+interceptors@0.35.6/node_modules/@mswjs/interceptors/lib/node/chunk-RWGRRMVU.mjs:236:27)
    at [getResponseCache] (./node_modules/.pnpm/@hono+node-server@1.13.0_hono@4.6.1/node_modules/@hono/node-server/dist/index.mjs:202:36)
    at new _Response (./node_modules/.pnpm/@hono+node-server@1.13.0_hono@4.6.1/node_modules/@hono/node-server/dist/index.mjs:210:31)
    at compress2 (./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/middleware/compress/index.js:19:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async dispatch (./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/compose.js:29:17)
    at async dispatch (./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/compose.js:29:17)
    at async ./node_modules/.pnpm/hono@4.6.1/node_modules/hono/dist/hono-base.js:200:25
    at async responseViaResponseObject (./node_modules/.pnpm/@hono+node-server@1.13.0_hono@4.6.1/node_modules/@hono/node-server/dist/index.mjs:339:13)

(we are serving our application with hono)