v14 → v15 に
原因は fetch の
何が変わったのか(v14 と v15 の違い)
Next.js 14 の App Router では、fetch() はforce-cache として
// v14: キャッシュオプションを書かなくても force-cache として動いていた
const res = await fetch('https://api.example.com/data');
Next.js 15.0.0 リリースノート に "Breaking: Disable automatic fetch caching" とある。no-store 相当)に
// v15: 同じコードが毎回 origin にリクエストを飛ばすようになった
const res = await fetch('https://api.example.com/data');
掲載時点fetch のauto no cache)は、no-store とnext build のときに 1 回だけno-store 相当」が
やらかした
NetaPair のfetch に
// 問題だったコード(v14 のときは force-cache でキャッシュされていた)
const statsRes = await fetch(`${process.env.API_BASE_URL}/api/stats/summary`);
const matchesRes = await fetch(`${process.env.API_BASE_URL}/api/matches/recent`);
v15 に
案のgrep -r "await fetch" --include= を
移行チェックリスト(4 パターン)
上の grep のno-store、revalidate: 60、force-cache に
1. 毎回
const res = await fetch(url, { cache: 'no-store' });
2. 一定間隔で
// 60 秒後に再バリデート
const res = await fetch(url, { next: { revalidate: 60 } });
3. ビルド
const res = await fetch(url, { cache: 'force-cache' });
4. ページ
// app/admin/stats/page.tsx の先頭に
export const dynamic = 'force-dynamic';
パターン 4 は
紛らわしい: no-cache と no-store は別物
最初に no-cache を
| オプション | キャッシュ保存 | 使用前の再検証 | 実際の動作 |
|---|---|---|---|
force-cache | する | しない | 永続キャッシュ |
no-cache | する | 毎回する | 保存した上でサーバーに確認 |
no-store | しない | しない | 常に origin から取得 |
no-store のno-cache はno-cache と no-store の
まとめ
- v14 → v15 で
fetchのデフォルトが force-cache→no-store相当に変わった 「キャッシュオプションを 書いていない fetch」が 全て 影響を 受ける - まず
grep -r "await fetch"で洗い出し、 全箇所に 意図を 明示する no-cacheとno-storeは別物。 「毎回最新を 取る」は no-store- 明示的に
書いておけば バージョン 依存の 挙動から 解放される