Skip to content

Commit

Permalink
fix(remix): Pass loadContext through wrapped document request funct…
Browse files Browse the repository at this point in the history
…ion (#8268)

Ensure that the loadContext created in the remix server is passed
through to `app/entry.server.ts` in the document request handler.

Fixes issue #8265.
  • Loading branch information
dawnmist committed Jun 1, 2023
1 parent 6208e57 commit c368bc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions packages/remix/src/utils/instrumentServer.ts
Expand Up @@ -113,14 +113,15 @@ function makeWrappedDocumentRequestFunction(
responseStatusCode: number,
responseHeaders: Headers,
context: Record<symbol, unknown>,
loadContext?: Record<string, unknown>,
): Promise<Response> {
let res: Response;

const activeTransaction = getActiveTransaction();
const currentScope = getCurrentHub().getScope();

if (!currentScope) {
return origDocumentRequestFunction.call(this, request, responseStatusCode, responseHeaders, context);
return origDocumentRequestFunction.call(this, request, responseStatusCode, responseHeaders, context, loadContext);
}

try {
Expand All @@ -133,7 +134,14 @@ function makeWrappedDocumentRequestFunction(
},
});

res = await origDocumentRequestFunction.call(this, request, responseStatusCode, responseHeaders, context);
res = await origDocumentRequestFunction.call(
this,
request,
responseStatusCode,
responseHeaders,
context,
loadContext,
);

span?.finish();
} catch (err) {
Expand Down
10 changes: 7 additions & 3 deletions packages/remix/src/utils/types.ts
Expand Up @@ -127,9 +127,13 @@ export interface ServerBuild {
}

export interface HandleDocumentRequestFunction {
(request: RemixRequest, responseStatusCode: number, responseHeaders: Headers, context: EntryContext):
| Promise<Response>
| Response;
(
request: RemixRequest,
responseStatusCode: number,
responseHeaders: Headers,
context: EntryContext,
loadContext?: AppLoadContext,
): Promise<Response> | Response;
}

export interface HandleDataRequestFunction {
Expand Down

0 comments on commit c368bc8

Please sign in to comment.