Skip to content
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

Fix normalization of .rsc extension #46043

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions packages/next/src/shared/lib/router/utils/app-paths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { normalizeRscPath } from './app-paths'

describe('normalizeRscPath', () => {
describe('enabled', () => {
it('should normalize url with .rsc', () => {
expect(normalizeRscPath('/test.rsc', true)).toBe('/test')
})
it('should normalize url with .rsc and querystring', () => {
expect(normalizeRscPath('/test.rsc?abc=def', true)).toBe('/test?abc=def')
})
})
describe('disabled', () => {
it('should normalize url with .rsc', () => {
expect(normalizeRscPath('/test.rsc', false)).toBe('/test.rsc')
})
it('should normalize url with .rsc and querystring', () => {
expect(normalizeRscPath('/test.rsc?abc=def', false)).toBe(
'/test.rsc?abc=def'
)
})
})
})
8 changes: 7 additions & 1 deletion packages/next/src/shared/lib/router/utils/app-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ export function normalizeAppPath(route: string) {
}

export function normalizeRscPath(pathname: string, enabled?: boolean) {
return enabled ? pathname.replace(/\.rsc($|\?)/, '') : pathname
return enabled
? pathname.replace(
/\.rsc($|\?)/,
// $1 ensures `?` is preserved
'$1'
)
: pathname
}