Replies: 2 comments
-
Finally figured it out. What gave it away is adding these logs:
Logs:
which then clicked... because I am importing the same file Super unintuitive, but makes sense. You need to use |
Beta Was this translation helpful? Give feedback.
-
It is loaded exactly twice. When your server module imports Here's an explanation of the problem: remix-run/remix#9790 (comment), and here's a workaround: remix-run/remix#9790 (reply in thread). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Note
I understand why this would happen it development build. But this issue describes production setup.
I am using react-router with Fastify, i.e. Fastify simply loads the
react-router
build:There is a file that's imported by Fastify entry script, but also referenced inside react-router project (
app/services/shutdownHandler.server.ts
). The contents of this file is:What I would expect is that when the program starts, I should see log:
and that's it. ("CREATE SHUTDOWN HANDLER" is printed when the
createShutdownHandler
is invoked).What actually is happening is this:
Notice that the second time
SHUTDOWN HANDLER
is printed,globalThis.foo
is no longer undefined but set to "bar".So somehow, the same module is being imported multiple/executed multiple times when it is shared this way between Fastify entry script and the react-router.
It is a major issue since it basically means that
shutdownHandler
is not shared between the two.I worked around by storing
shutdownHandler
inglobalThis
, but flagging as a bug.Beta Was this translation helpful? Give feedback.
All reactions