Replies: 4 comments 1 reply
-
I've thought about adding load context here, maybe one day we will, but you should be able to do anything you need to do inside the |
Beta Was this translation helpful? Give feedback.
-
Hi @ryanflorence and thanks for the great work on Remix ! If I understand it right, there's actually (at least) one big difference between My use case is to commit the session (and save it to my remote session store). If I do this in For now I'm using a global LRU cache, to access the session in Am I missing something ? Cheers ! |
Beta Was this translation helpful? Give feedback.
-
I need to inject a logger object (with Request information enclosed, so it can't be a global like console.log) during SSR. On the client it is replaced by a brand new logger instance. This is my express-based workaround to pass objects from the express context into the server rendering phase. This is a very hacky one but using a LRU cache is not feasible in my case. Proceed with caution: // server.ts
// first inline createRemixRequest, we need access to the request returned by createRemixRequest
const request = createRemixRequest(req)
request.__my_custom_logger = ... // use request instead of loadContext, as it is not currently supported
const response = await handleRequest(
request,
loadContext,
)
... // entry.server.ts
// we can't do remixContext.__my_custom_logger = value because the context is destructured
// before being passed to RemixEntryContext/
// so we tunnel it through appState
remixContext.appState.__my_custom_logger = request.__my_custom_logger // root.tsx
const remixContext = useContext(RemixEntryContext) // RemixEntryContext is exported from /dist,
// the export could break at any time
const serverLogger = remixContext?.appState.__my_custom_logger |
Beta Was this translation helpful? Give feedback.
-
I missed this discussion until I created a similar one. +1 |
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.
-
What is the new or updated feature that you are suggesting?
access
loadContext
fromhandleDocumentRequest
Why should this feature be included?
For custom express services, it is very important to be able to access
req
andres
, not only in theloader
function, but also inhandleDocumentRequest
!Beta Was this translation helpful? Give feedback.
All reactions