Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(nextjs): fix createRouteManifest with basePath #17838

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
seoyeon9888 wants to merge 2 commits into getsentry:develop
base: develop
Choose a base branch
Loading
from seoyeon9888:fix/next-sentry-create-route-manifest-basepath-bug
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/nextjs/src/config/manifest/createRouteManifest.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export type CreateRouteManifestOptions = {
* By default, route groups are stripped from paths following Next.js convention.
*/
includeRouteGroups?: boolean;
/**
* Base path for the application, if any. This will be prefixed to all routes.
*/
basePath?: string;
};

let manifestCache: RouteManifest | null = null;
Expand Down Expand Up @@ -192,7 +196,7 @@ export function createRouteManifest(options?: CreateRouteManifestOptions): Route
return manifestCache;
}

const { dynamicRoutes, staticRoutes } = scanAppDirectory(targetDir, '', options?.includeRouteGroups);
const { dynamicRoutes, staticRoutes } = scanAppDirectory(targetDir, options?.basePath, options?.includeRouteGroups);
Copy link

@cursor cursor bot Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Route Manifest Cache and Base Path Handling

The createRouteManifest cache doesn't invalidate when the basePath option changes, leading to stale manifests with incorrect route prefixes. Also, passing options?.basePath directly to scanAppDirectory can prefix routes with 'undefined/' when basePath is not provided.

Fix in Cursor Fix in Web


const manifest: RouteManifest = {
dynamicRoutes,
Expand Down
4 changes: 3 additions & 1 deletion packages/nextjs/src/config/withSentryConfig.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ function getFinalConfigObject(

let routeManifest: RouteManifest | undefined;
if (!userSentryOptions.disableManifestInjection) {
routeManifest = createRouteManifest();
routeManifest = createRouteManifest({
basePath: incomingUserNextConfigObject.basePath,
});
}

setUpBuildTimeVariables(incomingUserNextConfigObject, userSentryOptions, releaseName);
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// about page
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// API test page
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// root page
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// users id dynamic page
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import path from 'path';
import { describe, expect, test } from 'vitest';
import { createRouteManifest } from '../../../../../src/config/manifest/createRouteManifest';

describe('basePath', () => {
test('should generate routes with base path prefix', () => {
const manifest = createRouteManifest({
basePath: '/my-app',
appDirPath: path.join(__dirname, 'app')
});

expect(manifest).toEqual({
staticRoutes: [
{ path: '/my-app' },
{ path: '/my-app/about' },
{ path: '/my-app/api/test' }
],
dynamicRoutes: [
{
path: '/my-app/users/:id',
regex: '^/my-app/users/([^/]+)$',
paramNames: ['id'],
}
],
});
});

test('should validate dynamic route regex with base path', () => {
const manifest = createRouteManifest({
basePath: '/my-app',
appDirPath: path.join(__dirname, 'app')
});

const dynamicRoute = manifest.dynamicRoutes.find(route => route.path === '/my-app/users/:id');
const regex = new RegExp(dynamicRoute?.regex ?? '');

// Should match valid paths with base path
expect(regex.test('/my-app/users/123')).toBe(true);
expect(regex.test('/my-app/users/john-doe')).toBe(true);

// Should not match paths without base path
expect(regex.test('/users/123')).toBe(false);

// Should not match invalid paths
expect(regex.test('/my-app/users/')).toBe(false);
expect(regex.test('/my-app/users/123/extra')).toBe(false);
expect(regex.test('/my-app/user/123')).toBe(false);
});
});
Loading

AltStyle によって変換されたページ (->オリジナル) /