[PR #223] [MERGED] fix: resolve conditional React Hook calls in Link and Script shims #401

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/223
Author: @haddoumounir
Created: 3/2/2026
Status: Merged
Merged: 3/3/2026
Merged by: @southpolesteve

Base: mainHead: fix/rules-of-hooks-conditional-calls


📝 Commits (2)

  • 341e76a fix: resolve conditional React Hook calls in Link and Script shims
  • bd82431 fix: skip prefetch setup for dangerous href schemes

📊 Changes

2 files changed (+38 additions, -32 deletions)

View changed files

📝 packages/vinext/src/shims/link.tsx (+21 -14)
📝 packages/vinext/src/shims/script.tsx (+17 -18)

📄 Description

Summary

  • link.tsx: The dangerous-scheme early return was placed before all hooks (useState, useRef, useEffect, useCallback, useMemo), making them conditional. Moved the check to a boolean flag before hooks and the early return to after all hooks.
  • script.tsx: The SSR early return (typeof window === "undefined") was before useEffect, making it conditional. Moved useEffect before the SSR check since it never runs during SSR anyway.

Test plan

  • Verify dangerous scheme blocking still works in <Link> (e.g. javascript: hrefs render inert <a>)
  • Verify <Script> SSR rendering still works for beforeInteractive strategy
  • Verify no React warnings about conditional hooks in dev mode
  • Run existing test suite

🔄 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/223 **Author:** [@haddoumounir](https://github.com/haddoumounir) **Created:** 3/2/2026 **Status:** ✅ Merged **Merged:** 3/3/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/rules-of-hooks-conditional-calls` --- ### 📝 Commits (2) - [`341e76a`](https://github.com/cloudflare/vinext/commit/341e76a780e618711883c0877b911a085c08862c) fix: resolve conditional React Hook calls in Link and Script shims - [`bd82431`](https://github.com/cloudflare/vinext/commit/bd82431eabc67647686b67f926d8ad06c17c2c04) fix: skip prefetch setup for dangerous href schemes ### 📊 Changes **2 files changed** (+38 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/shims/link.tsx` (+21 -14) 📝 `packages/vinext/src/shims/script.tsx` (+17 -18) </details> ### 📄 Description ## Summary - **link.tsx**: The dangerous-scheme early return was placed before all hooks (`useState`, `useRef`, `useEffect`, `useCallback`, `useMemo`), making them conditional. Moved the check to a boolean flag before hooks and the early return to after all hooks. - **script.tsx**: The SSR early return (`typeof window === "undefined"`) was before `useEffect`, making it conditional. Moved `useEffect` before the SSR check since it never runs during SSR anyway. ## Test plan - [ ] Verify dangerous scheme blocking still works in `<Link>` (e.g. `javascript:` hrefs render inert `<a>`) - [ ] Verify `<Script>` SSR rendering still works for `beforeInteractive` strategy - [ ] Verify no React warnings about conditional hooks in dev mode - [ ] Run existing test suite --- <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:38 +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#401
No description provided.