-
Notifications
You must be signed in to change notification settings - Fork 31.2k
test(instant-validation): document usePathname() stack-trace attribution today #94422
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
Draft
aurorascharff
wants to merge
5
commits into
canary
Choose a base branch
from
aurorascharff/use-pathname-stack-trace-fixtures
base: canary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
08b7e6c
test(instant-validation): add fixtures for usePathname() stack-trace …
aurorascharff 73ba110
trim fixture descriptions, follow existing test conventions
aurorascharff d7285c6
use it.failing with correct stack assertion per Sebbie's review
aurorascharff 3e310c5
fix: use regular assertions instead of inline snapshots in it.failing
aurorascharff 18567a9
remove dev usePathname test (moved to #94423)
aurorascharff 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
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
.../app/(default)/pathname/invalid-use-pathname-deep-component/[one]/[two]/inner-wrapper.tsx
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,11 @@ | ||
| 'use client' | ||
|
|
||
| import { PathnameReader } from './pathname-reader' | ||
|
|
||
| export function InnerWrapper() { | ||
| return ( | ||
| <p> | ||
| Current path: <PathnameReader /> | ||
| </p> | ||
| ) | ||
| } |
11 changes: 11 additions & 0 deletions
11
...app/(default)/pathname/invalid-use-pathname-deep-component/[one]/[two]/middle-wrapper.tsx
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,11 @@ | ||
| 'use client' | ||
|
|
||
| import { InnerWrapper } from './inner-wrapper' | ||
|
|
||
| export function MiddleWrapper() { | ||
| return ( | ||
| <div> | ||
| <InnerWrapper /> | ||
| </div> | ||
| ) | ||
| } |
11 changes: 11 additions & 0 deletions
11
.../app/(default)/pathname/invalid-use-pathname-deep-component/[one]/[two]/outer-wrapper.tsx
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,11 @@ | ||
| 'use client' | ||
|
|
||
| import { MiddleWrapper } from './middle-wrapper' | ||
|
|
||
| export function OuterWrapper() { | ||
| return ( | ||
| <section> | ||
| <MiddleWrapper /> | ||
| </section> | ||
| ) | ||
| } |
29 changes: 29 additions & 0 deletions
29
...ion-build/app/(default)/pathname/invalid-use-pathname-deep-component/[one]/[two]/page.tsx
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,29 @@ | ||
| import type { Instant } from 'next' | ||
| import { OuterWrapper } from './outer-wrapper' | ||
|
|
||
| export const unstable_instant: Instant = { | ||
| level: 'experimental-error', | ||
| unstable_samples: [ | ||
| { | ||
| params: { | ||
| one: '123', | ||
| // two: <missing> | ||
| }, | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| export default function Page() { | ||
| return ( | ||
| <main> | ||
| <p> | ||
| usePathname() called from a Client Component nested three wrapper | ||
| components deep on a route with dynamic params where not all params are | ||
| provided in the sample. The build-time validation error should still | ||
| point at the actual call site in the user's source, not at a generic{' '} | ||
| <code>{'<unknown>'}</code> frame. | ||
| </p> | ||
| <OuterWrapper /> | ||
| </main> | ||
| ) | ||
| } |
8 changes: 8 additions & 0 deletions
8
...pp/(default)/pathname/invalid-use-pathname-deep-component/[one]/[two]/pathname-reader.tsx
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,8 @@ | ||
| 'use client' | ||
|
|
||
| import { usePathname } from 'next/navigation' | ||
|
|
||
| export function PathnameReader() { | ||
| const pathname = usePathname() | ||
| return <span data-testid="pathname">{pathname}</span> | ||
| } |
28 changes: 28 additions & 0 deletions
28
...pp/(default)/pathname/invalid-use-pathname-missing-params-no-wrapper/[one]/[two]/page.tsx
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,28 @@ | ||
| import type { Instant } from 'next' | ||
| import { PathnameReader } from './pathname-reader' | ||
|
|
||
| export const unstable_instant: Instant = { | ||
| level: 'experimental-error', | ||
| unstable_samples: [ | ||
| { | ||
| params: { | ||
| one: '123', | ||
| // two: <missing> | ||
| }, | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| export default function Page() { | ||
| return ( | ||
| <main> | ||
| <p> | ||
| usePathname() called directly at the top of a Client Component body (no{' '} | ||
| <code>ensureThrows()</code> wrapper) on a route with dynamic params | ||
| where not all params are provided in the sample. The build-time | ||
| validation error should point at the call site in the user's source. | ||
| </p> | ||
| <PathnameReader /> | ||
| </main> | ||
| ) | ||
| } |
8 changes: 8 additions & 0 deletions
8
...)/pathname/invalid-use-pathname-missing-params-no-wrapper/[one]/[two]/pathname-reader.tsx
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,8 @@ | ||
| 'use client' | ||
|
|
||
| import { usePathname } from 'next/navigation' | ||
|
|
||
| export function PathnameReader() { | ||
| const pathname = usePathname() | ||
| return <span data-testid="pathname">{pathname}</span> | ||
| } |
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
14 changes: 14 additions & 0 deletions
14
...2e/app-dir/instant-validation/app/default/invalid-use-pathname-no-samples/[slug]/page.tsx
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,14 @@ | ||
| import { PathnameLabel } from './pathname-label' | ||
|
|
||
| // No `unstable_instant` config at all — the [slug] param becomes a fallback | ||
| // route param during validation, which means usePathname() suspends. This is | ||
| // the natural user shape and matches the test-app's repro at | ||
| // `88-client-use-pathname/[slug]/page.tsx`. | ||
|
|
||
| export default function Page() { | ||
| return ( | ||
| <main> | ||
| <PathnameLabel /> | ||
| </main> | ||
| ) | ||
| } |
8 changes: 8 additions & 0 deletions
8
.../instant-validation/app/default/invalid-use-pathname-no-samples/[slug]/pathname-label.tsx
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,8 @@ | ||
| 'use client' | ||
|
|
||
| import { usePathname } from 'next/navigation' | ||
|
|
||
| export function PathnameLabel() { | ||
| const pathname = usePathname() | ||
| return <span data-testid="pathname-label">{pathname}</span> | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1893,6 +1893,50 @@ describe('instant validation', () => { | |
| expectNoBuildValidationErrors(result) | ||
| } | ||
| }) | ||
|
|
||
| it('invalid - usePathname() in a client component on a route with a fallback param', async () => { | ||
| if (!isNextDev) { | ||
| // Build-mode coverage lives in | ||
| // test/e2e/app-dir/instant-validation-build/instant-validation-build.test.ts | ||
| // under the `pathname` describe block. This test asserts the dev | ||
| // overlay's frame attribution. | ||
| return | ||
| } | ||
| if (isClientNav) { | ||
| // The bug we're capturing only manifests on initial load, where the | ||
| // dev validation runs server-side and the React stack is what gets | ||
| // surfaced. Skip the client-nav case so the inline snapshot below | ||
| // doesn't have to capture two different shapes. | ||
| return | ||
| } | ||
| // The fixture lives under `default/` (no root Suspense above body) so | ||
| // the validation hole isn't swallowed before the Insight can fire. | ||
| // `[slug]` is a fallback route param with no `unstable_samples`, so | ||
| // `usePathname()` suspends during dev validation — mirroring the | ||
| // test-app's repro at `88-client-use-pathname/[slug]`. | ||
| const browser = await navigateTo( | ||
| '/default/invalid-use-pathname-no-samples/123' | ||
| ) | ||
| // Snapshot the dev redbox shape so the bug surface is visible: | ||
| // today the overlay reports the parent page.tsx's render JSX as the | ||
| // source, not the `usePathname()` call inside pathname-label.tsx, | ||
| // and routes the user toward Cache / Stream / Block cards even | ||
| // though `usePathname` is URL data, not cacheable data. | ||
| await expect(browser).toDisplayCollapsedRedbox(` | ||
| { | ||
| "code": "E1265", | ||
| "description": "Next.js encountered uncached data during prerendering.", | ||
| "environmentLabel": "Server", | ||
| "label": "Blocking Route", | ||
| "source": "app/default/invalid-use-pathname-no-samples/[slug]/page.tsx (11:7) @ Page | ||
| > 11 | <PathnameLabel /> | ||
| | ^", | ||
| "stack": [ | ||
| "Page app/default/invalid-use-pathname-no-samples/[slug]/page.tsx (11:7)", | ||
| ], | ||
| } | ||
| `) | ||
| }) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should include a dev assertion to ensure there is a proper stack.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like this? d7285c6 |
||
| }) | ||
|
|
||
| describe('client errors', () => { | ||
|
|
||
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.
That doesn't really tell us stack attribution is working because it's just the sync error from misuing samples. The codeframe is the one we finally want. But it's broken at the moment.