-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(remix): Register remix route provider #23791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad36553
feat(remix): Register a route provider outside the tracing integration
logaretm 798a41c
ref(remix): Import the route provider API from `@sentry/core/browser`
logaretm 4884a18
ref(remix): Import the route provider API from `@sentry/react`
logaretm a9e340c
ref(remix): Pass the route provider as the `routeProvider` option
logaretm 6276e25
test(remix): Cover route resolution through the route provider
logaretm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...es/e2e-tests/test-applications/create-remix-app-express/app/routes/route-provider.$id.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import * as Sentry from '@sentry/remix'; | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| export default function RouteProvider() { | ||
| const [route, setRoute] = useState<string>(); | ||
|
|
||
| useEffect(() => { | ||
| setRoute(Sentry.resolveCurrentRoute() ?? 'unresolved'); | ||
| }, []); | ||
|
|
||
| return <div id="resolved-route">{route}</div>; | ||
| } |
9 changes: 9 additions & 0 deletions
9
...ackages/e2e-tests/test-applications/create-remix-app-express/tests/route-provider.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| // The route provider is backed by the manifest the Vite plugin injects into the client bundle, so this | ||
| // fails if that manifest never reaches the browser. | ||
| test('resolves the parameterized route through the route provider', async ({ page }) => { | ||
| await page.goto('/route-provider/123'); | ||
|
|
||
| await expect(page.locator('#resolved-route')).toHaveText('/route-provider/:id'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { RouteProvider } from '@sentry/react'; | ||
| import { createUrlRouteProvider } from '@sentry/react'; | ||
| import { maybeParameterizeRemixRoute } from './remixRouteParameterization'; | ||
|
|
||
| /** | ||
| * A route provider backed by the route manifest the Vite plugin injects at build time. | ||
| * | ||
| * The manifest is on the global object before `Sentry.init` runs, so this needs no router and no | ||
| * tracing integration: registering it is what lets anything else in the SDK name a route. | ||
| */ | ||
| export function createRemixRouteProvider(): RouteProvider { | ||
| return createUrlRouteProvider(url => maybeParameterizeRemixRoute(url.pathname)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { GLOBAL_OBJ } from '@sentry/core'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
| import { createRemixRouteProvider } from '../../src/client/routeProvider'; | ||
|
|
||
| const globalWithInjectedManifest = GLOBAL_OBJ as typeof GLOBAL_OBJ & { | ||
| _sentryRemixRouteManifest: string | undefined; | ||
| }; | ||
|
|
||
| const MANIFEST = JSON.stringify({ | ||
| staticRoutes: [{ path: '/about' }], | ||
| dynamicRoutes: [{ path: '/users/:id', regex: '^/users/([^/]+)$', paramNames: ['id'] }], | ||
| }); | ||
|
|
||
| let originalDocument: unknown; | ||
|
|
||
| describe('createRemixRouteProvider', () => { | ||
| beforeEach(() => { | ||
| globalWithInjectedManifest._sentryRemixRouteManifest = MANIFEST; | ||
| originalDocument = (GLOBAL_OBJ as { document?: unknown }).document; | ||
| // `resolveCurrentRoute` reads `document.location.href`. | ||
| (GLOBAL_OBJ as { document?: unknown }).document = { location: { href: 'https://example.com/users/42' } }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| globalWithInjectedManifest._sentryRemixRouteManifest = undefined; | ||
| (GLOBAL_OBJ as { document?: unknown }).document = originalDocument; | ||
| }); | ||
|
|
||
| it('parameterizes a URL from the build-time manifest', () => { | ||
| expect(createRemixRouteProvider().resolveRoute(new URL('https://example.com/users/42'))).toBe('/users/:id'); | ||
| }); | ||
|
|
||
| it('resolves a static route', () => { | ||
| expect(createRemixRouteProvider().resolveRoute(new URL('https://example.com/about'))).toBe('/about'); | ||
| }); | ||
|
|
||
| it('resolves the current route from the document location', () => { | ||
| expect(createRemixRouteProvider().resolveCurrentRoute()).toBe('/users/:id'); | ||
| }); | ||
|
|
||
| it('returns undefined for a URL the manifest does not know', () => { | ||
| expect(createRemixRouteProvider().resolveRoute(new URL('https://example.com/nope/deep'))).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined when the manifest was never injected', () => { | ||
| globalWithInjectedManifest._sentryRemixRouteManifest = undefined; | ||
|
|
||
| expect(createRemixRouteProvider().resolveRoute(new URL('https://example.com/users/42'))).toBeUndefined(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.