Docs
Protocol Verified

[FIX-005] History Origin Mismatch

Forcing HashHistory in blob: environments to comply with Same-Origin Policy.

PRID: 1115
VERIFIED
1 min read

[FIX-005] History Origin Mismatch (Blob Security)

📝 Problem Background

When using TanStack Router or React Router in the AI Studio preview window (running under the blob: protocol), the console shows an error: Failed to execute 'replaceState' on 'History': A history state object with URL 'https://ai.studio/...' cannot be created in a document with origin 'https://...'

🧪 Effort Metrics

  • Attempt Count: 4
  • Time Spent: 60 min
  • Complexity: ⭐⭐⭐⭐ (Hard)

🔍 Root Cause Analysis

  1. Protocol Mismatch: The sandbox preview page runs on a blob:https://... origin, while the routing library attempts to call history.replaceState to modify the URL to a standard https://....
  2. Same-Origin Policy: The browser prohibits redirecting or replacing history from a blob: protocol to a physical https: address.

🛠️ Fix Strategy

Protocol Switcher:

  • Environment Detection: Identify if the current environment is a blob: preview.
  • Forced Downgrade: In this special environment, forcibly use createMemoryHistory or createHashHistory.
  • Vite Adaptation: Set base: "./" in vite.config.ts to ensure relative path resolution.

Status: Archived

Authority Distribution

Share this technical artifact