-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add routeManifestInjection option to exclude routes from client bundle #18798
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
Merged
logaretm
merged 6 commits into
develop
from
awad/js-1414-explore-alternatives-to-client-injected-route-manifest
Jan 14, 2026
+267
−18
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e515a8
feat: added routeManifestInjection exclude options to disable manifes…
logaretm f338983
fix: lint
logaretm 8919cc7
fix: correctly priortize the new option
logaretm 7acc2c8
fix: use match instead and export fn for testing
logaretm 9fb1f8a
chore: added deprecation notices for v11
logaretm fba9871
refactor: use isMatchingPattern util for consistent SDK behavior
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
164 changes: 164 additions & 0 deletions
164
packages/nextjs/test/config/manifest/excludeRoutesFromManifest.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,164 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import type { RouteManifest } from '../../../src/config/manifest/types'; | ||
| import { filterRouteManifest } from '../../../src/config/withSentryConfig/getFinalConfigObjectUtils'; | ||
|
|
||
| describe('routeManifestInjection.exclude', () => { | ||
| const mockManifest: RouteManifest = { | ||
| staticRoutes: [ | ||
| { path: '/' }, | ||
| { path: '/about' }, | ||
| { path: '/admin' }, | ||
| { path: '/admin/dashboard' }, | ||
| { path: '/internal/secret' }, | ||
| { path: '/public/page' }, | ||
| ], | ||
| dynamicRoutes: [ | ||
| { path: '/users/:id', regex: '^/users/([^/]+)$', paramNames: ['id'] }, | ||
| { path: '/admin/users/:id', regex: '^/admin/users/([^/]+)$', paramNames: ['id'] }, | ||
| { path: '/secret-feature/:id', regex: '^/secret-feature/([^/]+)$', paramNames: ['id'] }, | ||
| ], | ||
| isrRoutes: ['/blog', '/admin/reports', '/internal/stats'], | ||
| }; | ||
|
|
||
| describe('with no filter', () => { | ||
| it('should return manifest unchanged', () => { | ||
| const result = filterRouteManifest(mockManifest, undefined); | ||
| expect(result).toEqual(mockManifest); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with string patterns', () => { | ||
| it('should exclude routes containing the string pattern (substring match)', () => { | ||
| const result = filterRouteManifest(mockManifest, ['/admin']); | ||
|
|
||
| // All routes containing '/admin' are excluded | ||
| expect(result.staticRoutes.map(r => r.path)).toEqual(['/', '/about', '/internal/secret', '/public/page']); | ||
| expect(result.dynamicRoutes.map(r => r.path)).toEqual(['/users/:id', '/secret-feature/:id']); | ||
| expect(result.isrRoutes).toEqual(['/blog', '/internal/stats']); | ||
| }); | ||
|
|
||
| it('should exclude routes matching multiple string patterns', () => { | ||
| const result = filterRouteManifest(mockManifest, ['/about', '/blog']); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual([ | ||
| '/', | ||
| '/admin', | ||
| '/admin/dashboard', | ||
| '/internal/secret', | ||
| '/public/page', | ||
| ]); | ||
| expect(result.isrRoutes).toEqual(['/admin/reports', '/internal/stats']); | ||
| }); | ||
|
|
||
| it('should match substrings anywhere in the route', () => { | ||
| // 'secret' matches '/internal/secret' and '/secret-feature/:id' | ||
| const result = filterRouteManifest(mockManifest, ['secret']); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual([ | ||
| '/', | ||
| '/about', | ||
| '/admin', | ||
| '/admin/dashboard', | ||
| '/public/page', | ||
| ]); | ||
| expect(result.dynamicRoutes.map(r => r.path)).toEqual(['/users/:id', '/admin/users/:id']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with regex patterns', () => { | ||
| it('should exclude routes matching regex', () => { | ||
| const result = filterRouteManifest(mockManifest, [/^\/admin/]); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual(['/', '/about', '/internal/secret', '/public/page']); | ||
| expect(result.dynamicRoutes.map(r => r.path)).toEqual(['/users/:id', '/secret-feature/:id']); | ||
| expect(result.isrRoutes).toEqual(['/blog', '/internal/stats']); | ||
| }); | ||
|
|
||
| it('should support multiple regex patterns', () => { | ||
| const result = filterRouteManifest(mockManifest, [/^\/admin/, /^\/internal/]); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual(['/', '/about', '/public/page']); | ||
| expect(result.isrRoutes).toEqual(['/blog']); | ||
| }); | ||
|
|
||
| it('should support partial regex matches', () => { | ||
| const result = filterRouteManifest(mockManifest, [/secret/]); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual([ | ||
| '/', | ||
| '/about', | ||
| '/admin', | ||
| '/admin/dashboard', | ||
| '/public/page', | ||
| ]); | ||
| expect(result.dynamicRoutes.map(r => r.path)).toEqual(['/users/:id', '/admin/users/:id']); | ||
| }); | ||
|
|
||
| it('should handle case-insensitive regex', () => { | ||
| const result = filterRouteManifest(mockManifest, [/ADMIN/i]); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual(['/', '/about', '/internal/secret', '/public/page']); | ||
| expect(result.dynamicRoutes.map(r => r.path)).toEqual(['/users/:id', '/secret-feature/:id']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with mixed patterns', () => { | ||
| it('should support both strings and regex', () => { | ||
| const result = filterRouteManifest(mockManifest, ['/about', /^\/admin/]); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual(['/', '/internal/secret', '/public/page']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with function filter', () => { | ||
| it('should exclude routes where function returns true', () => { | ||
| const result = filterRouteManifest(mockManifest, (route: string) => route.includes('admin')); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual(['/', '/about', '/internal/secret', '/public/page']); | ||
| expect(result.dynamicRoutes.map(r => r.path)).toEqual(['/users/:id', '/secret-feature/:id']); | ||
| expect(result.isrRoutes).toEqual(['/blog', '/internal/stats']); | ||
| }); | ||
|
|
||
| it('should support complex filter logic', () => { | ||
| const result = filterRouteManifest(mockManifest, (route: string) => { | ||
| // Exclude anything with "secret" or "internal" or admin routes | ||
| return route.includes('secret') || route.includes('internal') || route.startsWith('/admin'); | ||
| }); | ||
|
|
||
| expect(result.staticRoutes.map(r => r.path)).toEqual(['/', '/about', '/public/page']); | ||
| expect(result.dynamicRoutes.map(r => r.path)).toEqual(['/users/:id']); | ||
| expect(result.isrRoutes).toEqual(['/blog']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('edge cases', () => { | ||
| it('should handle empty manifest', () => { | ||
| const emptyManifest: RouteManifest = { | ||
| staticRoutes: [], | ||
| dynamicRoutes: [], | ||
| isrRoutes: [], | ||
| }; | ||
|
|
||
| const result = filterRouteManifest(emptyManifest, [/admin/]); | ||
| expect(result).toEqual(emptyManifest); | ||
| }); | ||
|
|
||
| it('should handle filter that excludes everything', () => { | ||
| const result = filterRouteManifest(mockManifest, () => true); | ||
|
|
||
| expect(result.staticRoutes).toEqual([]); | ||
| expect(result.dynamicRoutes).toEqual([]); | ||
| expect(result.isrRoutes).toEqual([]); | ||
| }); | ||
|
|
||
| it('should handle filter that excludes nothing', () => { | ||
| const result = filterRouteManifest(mockManifest, () => false); | ||
| expect(result).toEqual(mockManifest); | ||
| }); | ||
|
|
||
| it('should handle empty filter array', () => { | ||
| const result = filterRouteManifest(mockManifest, []); | ||
| expect(result).toEqual(mockManifest); | ||
| }); | ||
| }); | ||
| }); | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a todo(v11) comment for removal pls. We should add a tracking issue for v11 for removing all the deprecated types then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I will also add it for the other deprecated stuff.