handleDocumentRequest hook inside entry.server #2956
parisholley
started this conversation in
Proposals
Replies: 1 comment
-
alternatively, perhaps loadContext should always return an object (atm is undefined if you never set it on the adapter), and let the loaders potentially mutate it (allowing you to lazy instantiate shared resources) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
From what I understand, the
loadContext
functionality seems to be too far up in the stack (server adapter layer) vs being server agnostic. I should be able to expose abuildLoadContext()
function insideentry.server.tsx
, so that I can effectively bootstrap request resources.remix/packages/remix-server-runtime/server.ts
Lines 296 to 306 in 1c03a56
As you can see in that line in the runtime, we execute all of the loaders in parallel, however there is no way to initiate an asynchronous "pre loader" logic, which would allow us to build data/context and pass it to every loader before they begin.
Use Cases:
The
handleRequest
method could handle any type of "post loader" logic (eg: rollback/commit transactions), or the alternative to this idea is a truer middleware pattern.I initially attempted to piggyback off the request object in the loader function, however it is cloned every time so you cannot share anything between them. While there are other potential "global" node.js approaches (async hooks, domains) they are either experimental/deprecated or have performance trade offs.
Beta Was this translation helpful? Give feedback.
All reactions