Skip to content

Commit eb0d9f5

Browse files
authored
Remove static generation bail-out from usePathname (#42440)
x-ref: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1667504961058549) ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
1 parent c0a8c88 commit eb0d9f5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/next/client/components/navigation.ts

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export function useSearchParams() {
8787
* Get the current pathname. For example usePathname() on /dashboard?foo=bar would return "/dashboard"
8888
*/
8989
export function usePathname(): string | null {
90-
staticGenerationBailout('usePathname')
9190
return useContext(PathnameContext)
9291
}
9392

test/e2e/app-dir/app-static.test.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ describe('app-dir static/dynamic handling', () => {
5454
'dynamic-no-gen-params-ssr/[slug]/page.js',
5555
'dynamic-no-gen-params/[slug]/page.js',
5656
'hooks/use-pathname/[slug]/page.js',
57+
'hooks/use-pathname/slug.html',
58+
'hooks/use-pathname/slug.rsc',
5759
'hooks/use-search-params/[slug]/page.js',
5860
'ssr-auto/cache-no-store/page.js',
5961
'ssr-auto/fetch-revalidate-zero/page.js',
@@ -114,6 +116,11 @@ describe('app-dir static/dynamic handling', () => {
114116
srcRoute: '/blog/[author]/[slug]',
115117
dataRoute: '/blog/styfle/second-post.rsc',
116118
},
119+
'/hooks/use-pathname/slug': {
120+
dataRoute: '/hooks/use-pathname/slug.rsc',
121+
initialRevalidateSeconds: false,
122+
srcRoute: '/hooks/use-pathname/[slug]',
123+
},
117124
})
118125
expect(manifest.dynamicRoutes).toEqual({
119126
'/blog/[author]/[slug]': {
@@ -128,6 +135,12 @@ describe('app-dir static/dynamic handling', () => {
128135
fallback: false,
129136
routeRegex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'),
130137
},
138+
'/hooks/use-pathname/[slug]': {
139+
dataRoute: '/hooks/use-pathname/[slug].rsc',
140+
dataRouteRegex: '^\\/hooks\\/use\\-pathname\\/([^\\/]+?)\\.rsc$',
141+
fallback: null,
142+
routeRegex: '^\\/hooks\\/use\\-pathname\\/([^\\/]+?)(?:\\/)?$',
143+
},
131144
})
132145
})
133146
}
@@ -405,7 +418,8 @@ describe('app-dir static/dynamic handling', () => {
405418
}
406419
})
407420

408-
describe('usePathname', () => {
421+
// TODO: needs updating as usePathname should not bail
422+
describe.skip('usePathname', () => {
409423
if (isDev) {
410424
it('should bail out to client rendering during SSG', async () => {
411425
const res = await fetchViaHTTP(next.url, '/hooks/use-pathname/slug')

0 commit comments

Comments
 (0)