Skip to content

Commit

Permalink
Remove static generation bail-out from usePathname (#42440)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ijjk committed Nov 3, 2022
1 parent c0a8c88 commit eb0d9f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion packages/next/client/components/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export function useSearchParams() {
* Get the current pathname. For example usePathname() on /dashboard?foo=bar would return "/dashboard"
*/
export function usePathname(): string | null {
staticGenerationBailout('usePathname')
return useContext(PathnameContext)
}

Expand Down
16 changes: 15 additions & 1 deletion test/e2e/app-dir/app-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ describe('app-dir static/dynamic handling', () => {
'dynamic-no-gen-params-ssr/[slug]/page.js',
'dynamic-no-gen-params/[slug]/page.js',
'hooks/use-pathname/[slug]/page.js',
'hooks/use-pathname/slug.html',
'hooks/use-pathname/slug.rsc',
'hooks/use-search-params/[slug]/page.js',
'ssr-auto/cache-no-store/page.js',
'ssr-auto/fetch-revalidate-zero/page.js',
Expand Down Expand Up @@ -114,6 +116,11 @@ describe('app-dir static/dynamic handling', () => {
srcRoute: '/blog/[author]/[slug]',
dataRoute: '/blog/styfle/second-post.rsc',
},
'/hooks/use-pathname/slug': {
dataRoute: '/hooks/use-pathname/slug.rsc',
initialRevalidateSeconds: false,
srcRoute: '/hooks/use-pathname/[slug]',
},
})
expect(manifest.dynamicRoutes).toEqual({
'/blog/[author]/[slug]': {
Expand All @@ -128,6 +135,12 @@ describe('app-dir static/dynamic handling', () => {
fallback: false,
routeRegex: normalizeRegEx('^\\/blog\\/([^\\/]+?)(?:\\/)?$'),
},
'/hooks/use-pathname/[slug]': {
dataRoute: '/hooks/use-pathname/[slug].rsc',
dataRouteRegex: '^\\/hooks\\/use\\-pathname\\/([^\\/]+?)\\.rsc$',
fallback: null,
routeRegex: '^\\/hooks\\/use\\-pathname\\/([^\\/]+?)(?:\\/)?$',
},
})
})
}
Expand Down Expand Up @@ -405,7 +418,8 @@ describe('app-dir static/dynamic handling', () => {
}
})

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

0 comments on commit eb0d9f5

Please sign in to comment.