[PR #1070] [MERGED] refactor(app-browser-entry): dedupe encoded JSON header parsing #1066

Closed
opened 2026-05-06 13:11:49 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1070
Author: @james-elicx
Created: 5/5/2026
Status: Merged
Merged: 5/5/2026
Merged by: @james-elicx

Base: mainHead: refactor/dedupe-encoded-json-header


📝 Commits (1)

  • 7e0b27c refactor(app-browser-entry): dedupe encoded JSON header parsing

📊 Changes

1 file changed (+27 additions, -18 deletions)

View changed files

📝 packages/vinext/src/server/app-browser-entry.ts (+27 -18)

📄 Description

Summary

  • Extract the repeated try { JSON.parse(decodeURIComponent(headerValue)) } catch { ... } pattern used to hydrate params from the X-Vinext-Params header into a single local helper, parseEncodedJsonHeader<T>(value: string | null): T | null.
  • Both call sites in packages/vinext/src/server/app-browser-entry.ts (the initial RSC hydration path and the in-flight navigation path) now share the helper.
  • Pure refactor — no behavior change.

Follow-up to #1049.

Files changed

  • packages/vinext/src/server/app-browser-entry.ts — adds the helper at the top of the file and updates the two call sites.

Notes on behavior preservation

The two original blocks had a subtle difference:

  • The first call site (initial RSC response) parsed the header and called applyClientParams(params) inside the same try, so the catch silently swallowed any error from applyClientParams as well.
  • The second call site only parsed.

The helper itself only handles parsing. To preserve the original error-swallowing semantics at the first call site, applyClientParams is wrapped in a small dedicated try/catch there. The helper does not log or surface errors — silent by design, matching the pre-existing behavior.

A quick grep -rn "JSON.parse(decodeURIComponent" packages/vinext/src/ confirmed the pattern only appears in this file, so a module-private helper (rather than a shared utility) is sufficient.

Test plan

  • pnpm vp test run tests/app-router.test.ts — 308 tests pass
  • pnpm fmt --write on the touched file
  • Manual diff review to confirm structural-only change

🤖 Generated with Claude Code


🔄 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/1070 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 5/5/2026 **Status:** ✅ Merged **Merged:** 5/5/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `refactor/dedupe-encoded-json-header` --- ### 📝 Commits (1) - [`7e0b27c`](https://github.com/cloudflare/vinext/commit/7e0b27c1f6fc3773ffa28ad19c313cd3f3751474) refactor(app-browser-entry): dedupe encoded JSON header parsing ### 📊 Changes **1 file changed** (+27 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/server/app-browser-entry.ts` (+27 -18) </details> ### 📄 Description ## Summary - Extract the repeated `try { JSON.parse(decodeURIComponent(headerValue)) } catch { ... }` pattern used to hydrate params from the `X-Vinext-Params` header into a single local helper, `parseEncodedJsonHeader<T>(value: string | null): T | null`. - Both call sites in `packages/vinext/src/server/app-browser-entry.ts` (the initial RSC hydration path and the in-flight navigation path) now share the helper. - Pure refactor — no behavior change. Follow-up to #1049. ## Files changed - `packages/vinext/src/server/app-browser-entry.ts` — adds the helper at the top of the file and updates the two call sites. ## Notes on behavior preservation The two original blocks had a subtle difference: - The first call site (initial RSC response) parsed the header **and** called `applyClientParams(params)` inside the same `try`, so the catch silently swallowed any error from `applyClientParams` as well. - The second call site only parsed. The helper itself only handles parsing. To preserve the original error-swallowing semantics at the first call site, `applyClientParams` is wrapped in a small dedicated `try/catch` there. The helper does not log or surface errors — silent by design, matching the pre-existing behavior. A quick `grep -rn "JSON.parse(decodeURIComponent" packages/vinext/src/` confirmed the pattern only appears in this file, so a module-private helper (rather than a shared utility) is sufficient. ## Test plan - [x] `pnpm vp test run tests/app-router.test.ts` — 308 tests pass - [x] `pnpm fmt --write` on the touched file - [x] Manual diff review to confirm structural-only change 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:49 +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#1066
No description provided.