[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
- Protocol Mismatch: The sandbox preview page runs on a
blob:https://...origin, while the routing library attempts to callhistory.replaceStateto modify the URL to a standardhttps://.... - Same-Origin Policy: The browser prohibits redirecting or replacing history from a
blob:protocol to a physicalhttps:address.
🛠️ Fix Strategy
Protocol Switcher:
- Environment Detection: Identify if the current environment is a
blob:preview. - Forced Downgrade: In this special environment, forcibly use
createMemoryHistoryorcreateHashHistory. - Vite Adaptation: Set
base: "./"invite.config.tsto ensure relative path resolution.
Status: Archived