[PR #79] [MERGED] fix(navigation): cache getServerSnapshot fallback in useSearchParams #292

Closed
opened 2026-05-06 12:39:01 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/79
Author: @gembleman
Created: 2/25/2026
Status: Merged
Merged: 2/27/2026
Merged by: @FredKSchott

Base: mainHead: fix/use-search-params-server-snapshot-cache


📝 Commits (2)

  • cf7d576 fix(navigation): cache getServerSnapshot fallback in useSearchParams
  • ea4b896 Refactor cached search params and pathname logic

📊 Changes

1 file changed (+20 additions, -12 deletions)

View changed files

📝 packages/vinext/src/shims/navigation.ts (+20 -12)

📄 Description

useSyncExternalStore compares snapshots with Object.is. The previous getServerSnapshot returned new URLSearchParams() on every call when no server context was available, producing a new object reference each time and triggering an infinite re-render loop in React.

Fix: introduce a module-level _cachedServerSearchParams that is allocated once and reused, matching the same referential-stability pattern already used by getSearchParamsSnapshot for the client snapshot.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/79 **Author:** [@gembleman](https://github.com/gembleman) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 2/27/2026 **Merged by:** [@FredKSchott](https://github.com/FredKSchott) **Base:** `main` ← **Head:** `fix/use-search-params-server-snapshot-cache` --- ### 📝 Commits (2) - [`cf7d576`](https://github.com/cloudflare/vinext/commit/cf7d576ea39314e0ce19a8e1af771bbc6a14bd3c) fix(navigation): cache getServerSnapshot fallback in useSearchParams - [`ea4b896`](https://github.com/cloudflare/vinext/commit/ea4b896c5e0e172a0f50d4b8a27eb906a42c1c75) Refactor cached search params and pathname logic ### 📊 Changes **1 file changed** (+20 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/shims/navigation.ts` (+20 -12) </details> ### 📄 Description useSyncExternalStore compares snapshots with Object.is. The previous getServerSnapshot returned `new URLSearchParams()` on every call when no server context was available, producing a new object reference each time and triggering an infinite re-render loop in React. Fix: introduce a module-level `_cachedServerSearchParams` that is allocated once and reused, matching the same referential-stability pattern already used by `getSearchParamsSnapshot` for the client snapshot. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:01 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#292
No description provided.