Skip to content
This repository was archived by the owner on Sep 15, 2026. It is now read-only.

fix(layout): Next.js 16 でページ遷移のスクロールを即座に戻す - #35

Merged
Uno-Takashi merged 1 commit into
mainfrom
fix/next16-scroll-behavior
Sep 15, 2026
Merged

Uno-Takashi merged 1 commit into
mainfrom
fix/next16-scroll-behavior

Conversation

@Uno-Takashi

Copy link
Copy Markdown
Member

背景

Next.js 15 以前は、SPA ナビゲーション中だけ scroll-behavior を一時的に auto へ
書き換えてから遷移していたため、アプリ側が scroll-behavior: smooth を全体に当てていても
ページ遷移は常に即座にトップへジャンプしていました。

Next.js 16 でこの上書きが既定で行われなくなりました。

このリポジトリは src/app/globals.css で html { scroll-behavior: smooth; } を指定しているため、
#30 で Next 16 に上げた結果、ページ遷移のたびにトップまで滑らかスクロールする挙動に変わっていました。

変更

<html> に data-scroll-behavior="smooth" を付けて、Next に従来どおりの上書きをさせます。

  • ページ遷移 → 即座(15 以前と同じ)
  • ページ内アンカーリンク → 滑らか(CSS の指定はそのまま有効)

確認

  • pnpm typecheck / pnpm lint / pnpm build 通過(prettier も --check 通過)
  • pnpm start で実起動し、配信される HTML に
    <html lang="ja" data-scroll-behavior="smooth"> が出ていることを確認

参考: Next.js 16 upgrade guide — Scroll Behavior Override

🤖 Generated with Claude Code

Next.js 15 and earlier temporarily forced `scroll-behavior: auto` during SPA
navigations so a route change always jumped to the top instantly, even when
the app set `scroll-behavior: smooth` globally. Next.js 16 stops doing that
override by default.

`globals.css` sets `scroll-behavior: smooth` on `html`, so after the upgrade
to Next 16 every route change animates a scroll to the top instead of moving
there immediately. Opting back in with `data-scroll-behavior="smooth"` keeps
in-page anchor links smooth while making navigation instant again, which is
the pre-upgrade behaviour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Uno-Takashi
Uno-Takashi merged commit ce0826a into main Sep 15, 2026
7 checks passed
@Uno-Takashi
Uno-Takashi deleted the fix/next16-scroll-behavior branch September 15, 2026 07:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant