Skip to content

makeWrappedRootLoader does not handle Response cases #5539

Closed
@augustuswm

Description

@augustuswm

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/remix

SDK Version

7.9.0

Framework Version

React 17.0.2

Link to Sentry event

No response

Steps to Reproduce

  1. Create a Remix project with a root loader that returns a response object (or uses the Remix provided json function).
export const loader: LoaderFunction = async () => {
  return json(
    { data_one: [], data_two: "a string" },
    { headers: { 'Cache-Control': 'max-age=300' } }
  )
}
  1. Configure Sentry via Sentry.init(...) in entry.server.tsx
  2. Load the root page in a browser
  3. Inspect __remixContext.routeData.root in dev tools and it will have the shape { sentryBaggage: string, sentryTrace: string, size: number } instead of containing the loader data.

This looks to be caused by the makeWrappedRootLoader function which handles the result of the origLoader as an Promise<AppData> | AppData instead of Promise<Response> | Response | Promise<AppData> | AppData:

function makeWrappedRootLoader(origLoader: DataFunction): DataFunction {
  return async function (this: unknown, args: DataFunctionArgs): Promise<Response | AppData> {
    const res = await origLoader.call(this, args);

    return { ...res, ...getTraceAndBaggage() };
  };
}

Expected Result

Data and ResponseInit settings are propagated when a Promise<Response> or Response is returned from the root loader.

Actual Result

Data and headers (or ResponseInit) data from the root loader are omitted from data on the client and the response respectively.

Metadata

Metadata

Assignees

Labels

Package: remixIssues related to the Sentry Remix SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions