-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scroll when loading.js/ts is used (#48986)
### What? Whenever you navigated and a page suspended through `loading` or an error happened caught by `error` in the first level of segments (e.g. `/dashboard` but not `/dashboard/settings`) scroll would not be applied. This happened because the focus and scroll handling component is rendered as part of `InnerLayoutRouter` and the Suspense / Error boundary was rendered **around** `InnerLayoutRouter`. This behavior is incorrect as we still want to immediately scroll to the place where the loading is rendered. This PR fixes the behavior by allowing the scroll to apply to loading / error too. ### How? Moved the scrolling component around the loading/error/innerlayout boundary and added tests.
- Loading branch information
1 parent
986039d
commit 905b62e
Showing
5 changed files
with
106 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/router-autoscroll/app/loading-scroll/loading.tsx
This file contains 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,13 @@ | ||
export default function Loading() { | ||
return ( | ||
<> | ||
<div id="loading-component">Loading component</div> | ||
{ | ||
// Repeat 500 elements | ||
Array.from({ length: 500 }, (_, i) => ( | ||
<div key={i}>Loading {i}...</div> | ||
)) | ||
} | ||
</> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
test/e2e/app-dir/router-autoscroll/app/loading-scroll/page.tsx
This file contains 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,17 @@ | ||
export const dynamic = 'force-dynamic' | ||
|
||
export default async function Page() { | ||
await new Promise((resolve) => setTimeout(resolve, 5000)) | ||
return ( | ||
<> | ||
<div style={{ display: 'none' }}>Content that is hidden.</div> | ||
<div id="content-that-is-visible">Content which is not hidden.</div> | ||
{ | ||
// Repeat 500 elements | ||
Array.from({ length: 500 }, (_, i) => ( | ||
<div key={i}>{i}</div> | ||
)) | ||
} | ||
</> | ||
) | ||
} |
This file contains 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 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