This pull request adjusts our experimental scroll restoration behavior to use `sessionStorage` as opposed to `History#replaceState` to track scroll position.
In addition, **it eliminates a scroll event listener** and only captures when a `pushState` event happens (thereby leaving state that needs snapshotted).
These merely adjusts implementation detail, and is covered by existing tests:
```
test/integration/scroll-back-restoration/
```
---
Fixes#16690Fixes#17073Fixes#20486
This ensures we render the locale domain on the `href` when using `next/link` previously the provided `href` was stilling being rendered which differed from the resulting `href` that was navigated to.
Fixes: https://github.com/vercel/next.js/issues/20612
This pull request adds an `elements.delete` operation to the `useIntersection`'s cleanup function: `unobserve`.
Without this delete operation, next.js holds onto an unreachable reference of every observed element indefinitely (automatically every Link and Image is observed, so that means every rendered Link and Image element adds to the leak). I found this memory leak when building out an infinite feed in next.js with thousands of Link elements.
The final code block of the `unobserve` function body:
```tsx
// Destroy observer when there's nothing left to watch:
if (elements.size === 0) {
observer.disconnect()
observers.delete(id)
}
```
Is effectively unreachable without this delete operation, as the `elements` map will never decrease in size as it is currently. This means that there will always be at least one IntersectionObserver instance in memory if useIntersection has been used once, regardless of if there are currently any components still using the hook.
This pull request makes `Router#push` and `Router#replace` function identically to `<Link />`, i.e. reset scroll when the new render is complete.
Users can opt out of this new behavior via:
```tsx
const path = '/my-page'
router.push(path, path, { scroll: false })
```
---
Fixes#3249
This ensures we detect domain specific locales and redirect them client-side. Tests have been added in the `i18n` suite to ensure the domain redirect is applied correctly during a client-side navigation
Fixes: https://github.com/vercel/next.js/issues/19174
This refactors to instead of throwing a specific error when a SSG data route 404s, we return it through props and render the 404 outside of the error handling flow. No additional tests have been added as existing tests should cover this.
Closes: https://github.com/vercel/next.js/issues/19243
This moves the scroll reset behavior to happen synchronously with the DOM commit, instead of a few ticks after the render completes.
This is necessary for components that read scroll state on mount.
---
Fixes#6462
This ensures the default path used for the `next/image` component includes the `basePath` when configured. Additional tests have also been added to ensure the image component is working correctly with `basePath` configured.
Fixes: https://github.com/vercel/next.js/issues/19711
This fixes `next/image` to properly ignore inherited styles applied to the `img` tag by a parent element.
Image styling should **always** be done by a wrapper element—not to the image itself!
---
Fixes#19817Fixes#19964
Fixes: https://github.com/vercel/next.js/issues/15278
> Bug report
> When using next dev with emacs, as you develop, emacs creates symbolic link files starting with .# as lock files. Next.js seems to attempt to load these but fails, spewing out errors constantly.
Prevents dev server from crashing when emacs creates lockfiles
tested with:
- GNU Emacs 27.1
- OSX 11.1
- Node v15.4.0
This removes `import type` usage from our core files since `import type` requires a higher TypeScript version than currently expected.
Fixes: https://github.com/vercel/next.js/issues/19300
This makes sure we don't generate the wrong locale source variant for the rewrite requiring a `/` on the end which won't ever be added causing the rewrite to never match. Additional tests have been added to ensure this specific rewrite is working correctly.
Fixes: https://github.com/vercel/next.js/issues/20508
This makes sure the query isn't dropped when doing a history navigation with i18n. Additional tests have been added to ensure this is working correctly as well.
Fixes: https://github.com/vercel/next.js/issues/20212
This ensures we show an error for string values for `revalidate` since we currently don't handle these and instead it results in `revalidate: false` being used. This also adds tests for our `revalidate` checks to ensure they are triggered correctly and not triggered for valid values.
x-ref: https://github.com/vercel/next.js/issues/20310
This makes sure redirects to the index route properly end with a trailing slash or don't based on the `trailingSlash` config to ensure an additional redirect doesn't need to take place un-necessarily.
Fixes: https://github.com/vercel/next.js/issues/19405
This ensures the pages-manifest only includes forward slashes and not backslashes when adding i18n page references, this also adds tests ensuring we don't regress on this in the i18n-support test suite.
Fixes: https://github.com/vercel/next.js/issues/20330
There's currently two bugs with the font optimization, but we'd really like to ship a stable version.
To unblock the stable release, we're **temporarily** reflagging this. It'll be unflagged on canary again!
Solves the following warning:
> (node:1484) [DEP_WEBPACK_MAIN_TEMPLATE_REQUIRE_FN] DeprecationWarning: MainTemplate.requireFn is deprecated (use "__webpack_require__")
Adds brief summary in Getting Started to explain the `pages/api` functionality. The intention here is reduce confusion to new users of Next.js as to what `pages/api` is and how it works.
This makes sure the `locale` doesn't cause the wrong `href` to be resolved, this also ensures route specificity is correct when loading dynamic routes in production mode.
Fixes: https://github.com/vercel/next.js/issues/19747
Currently if sizes is not defined, Next.js is setting sizes as:
```
(max-width: 640px) 640px, (max-width: 750px) 750px, (max-width: 828px) 828px, (max-width: 1080px) 1080px, (max-width: 1200px) 1200px, (max-width: 1920px) 1920px, (max-width: 2048px) 2048px, 3840px'
```
This pull request will make sizes be `100vw` by default, which will allow us to download "smaller" images than what's currently happening.
In a demo app I have, the difference is between downloading 488KB vs 1.4MB (in images)
Adds an err.sh link to the production build missing message. Also clears up `valid` as `production`.
Also fixes an edge case where an unhelpful error would be thrown because we checked for `.next` instead of `.next/BUILD_ID`
Added the out directory location as the list line during export to make sure people know where the files are output.
Fixes#19778Fixes#19788
## Why
Some users prefer to use a custom server implementation that handles body parsing. If they do this, they have no way to opt out of all body parsing in API Routes. Requests with bodies die if next's `bodyParser` is not disabled. Requests just hang forever.
Instead of adding [this config](https://nextjs.org/docs/api-routes/api-middlewares#custom-config) to every API Route, we do a simple check to avoid parsing the body twice.
Fixes#8315Fixes#7960
Nitpicky change, but the version string contained a double `|`, implying that there might be an empty value between `process.env.__NEXT_VERSION` and the environment variables.
* make the error message more clear if webpack config comes back undefined
* Update check and add test
* bump
* Update build-output test
Co-authored-by: JJ Kasper <jj@jjsweb.site>
This reverts #18921 and ensures that the Babel runtime is only inlined as an absolute path when using PnP as before, but then including the correction this resolution as implemented by @merceyz only in the PnP cases, while keeping the diff to a minimum.
Fixes#16173
## What
Restores handling of termination signals, `SIGTERM` and `SIGINT`, to allow graceful termination of next commands. Seems to have been removed during a child process refactor #6450, was this intentional?
## Why
Currently the command processes have to be forcefully killed. This would help those using Next.js with custom servers and tools like Docker and Kubernetes that rely on termination signals to shutdown instances.
---
Where would be a good location to add some tests? [test/integration/cli/test/index.test.js](fc98c13a2e/test/integration/cli/test/index.test.js)?
This updates the fallback locale for `locale: false` to be the `defaultLocale` instead of the currently active `locale` as it allows passing through URLs more seamlessly as a URL without the locale prefixed can be treated as the `defaultLocale` instead of having to worry if the locale matches the currently active locale. This also ensures `locale={false}` is tested in the i18n-support-catchall suite
Closes: https://github.com/vercel/next.js/issues/19048