mjackson / remix-the-web

Open source tools for Remix (or any framework!)
MIT License
712 stars 14 forks source link

Does it work with installGlobals? #5

Closed lukejagodzinski closed 2 months ago

lukejagodzinski commented 3 months ago

The project I'm working on is on Remix 2.8.1 and I wanted to use this package. After trying to figure out why it doesn't work as expected I found out that the issue is installGlobals() call which I think I need to use as we're not using remix-serve. It's a little bit confusing and I'm not sure whether I need to use it.

However, the question is, is there a way to make this package work with installGlobals() ? It looks like it's messing with the inheritance of classes.

lukejagodzinski commented 3 months ago

I did some investigation and it looks like the Remix implementation of Headers is at fault. It's using Proxy which totally messes the inheritance tree. Because of that any method that you override doesn't work and the Proxy method is being used instead. For now, I solved it by changing the way how installGlobals is being called:

import { installGlobals as remixInstallGlobals } from "@remix-run/node";

export function installGlobals() {
  const OriginalHeaders = global.Headers;
  remixInstallGlobals();
  global.Headers = OriginalHeaders;
}

This solves the problem.

mjackson commented 2 months ago

If you're on node 20 you shouldn't need installGlobals. If not, try using the undici library internally instead of our own polyfill and see if that helps:

installGlobals({ nativeFetch: true });
lukejagodzinski commented 2 months ago

Yep, I'm on Node 20 and I know that I don't have to use installGlobals but it's not my codebase and I'm not sure if after switching to udici it will work without memory leaks because of need to handle body of the POST requests. Thanks for the reply :)