Skip to content

Commit a9e340c

Browse files
committed
ref(remix): Pass the route provider as the routeProvider option
1 parent 4884a18 commit a9e340c

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎packages/remix/src/client/sdk.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Client } from '@sentry/core';
22
import { applySdkMetadata } from '@sentry/core';
3-
import { init as reactInit, setRouteProvider } from '@sentry/react';
3+
import { init as reactInit } from '@sentry/react';
44
import type { RemixOptions } from '../utils/remixOptions';
55
import { createRemixRouteProvider } from './routeProvider';
66

@@ -11,18 +11,14 @@ import { createRemixRouteProvider } from './routeProvider';
1111
*/
1212
export function init(options: RemixOptions): Client | undefined {
1313
const opts = {
14+
// The manifest is injected at build time, so route parameterization works from `init` on, even with
15+
// tracing disabled.
16+
routeProvider: createRemixRouteProvider(),
1417
...options,
1518
environment: options.environment || process.env.NODE_ENV,
1619
};
1720

1821
applySdkMetadata(opts, 'remix', ['remix', 'react']);
1922

20-
const client = reactInit(opts);
21-
22-
// Registered here rather than from the tracing integration so route parameterization does not
23-
// depend on tracing: the manifest is injected at build time, so anything that needs a route name
24-
// (bfcache metrics, web vitals) can resolve one even with tracing disabled.
25-
setRouteProvider(createRemixRouteProvider(), client);
26-
27-
return client;
23+
return reactInit(opts);
2824
}

‎packages/remix/test/index.client.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ describe('Client init()', () => {
4343
);
4444
});
4545

46+
it('passes the Remix route provider unless the user passed one', () => {
47+
init({});
48+
expect(reactInit).toHaveBeenLastCalledWith(
49+
expect.objectContaining({ routeProvider: expect.objectContaining({ resolveRoute: expect.any(Function) }) }),
50+
);
51+
52+
const routeProvider = { resolveRoute: () => '/custom', resolveCurrentRoute: () => '/custom' };
53+
init({ routeProvider });
54+
expect(reactInit).toHaveBeenLastCalledWith(expect.objectContaining({ routeProvider }));
55+
});
56+
4657
it('returns client from init', () => {
4758
expect(init({})).not.toBeUndefined();
4859
});

0 commit comments

Comments
 (0)