-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split router utils into smaller modules (#45451)Co-authored-by: Jan K…
…aifer <[email protected]> This makes sure that the entire module `shared/lib/router/router` isn't included in the final bundle, by splitting it into smaller utils. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/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` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) 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`](https://github.com/vercel/next.js/blob/canary/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) --------- Co-authored-by: Jan Kaifer <[email protected]>
- Loading branch information
Showing
11 changed files
with
246 additions
and
233 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
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
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
20 changes: 20 additions & 0 deletions
20
packages/next/src/shared/lib/router/utils/handle-smooth-scroll.ts
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,20 @@ | ||
/** | ||
* Run function with `scroll-behavior: auto` applied to `<html/>`. | ||
* This css change will be reverted after the function finishes. | ||
*/ | ||
export function handleSmoothScroll( | ||
fn: () => void, | ||
options: { dontForceLayout?: boolean } = {} | ||
) { | ||
const htmlElement = document.documentElement | ||
const existing = htmlElement.style.scrollBehavior | ||
htmlElement.style.scrollBehavior = 'auto' | ||
if (!options.dontForceLayout) { | ||
// In Chrome-based browsers we need to force reflow before calling `scrollTo`. | ||
// Otherwise it will not pickup the change in scrollBehavior | ||
// More info here: https://github.com/vercel/next.js/issues/40719#issuecomment-1336248042 | ||
htmlElement.getClientRects() | ||
} | ||
fn() | ||
htmlElement.style.scrollBehavior = existing | ||
} |
Oops, something went wrong.