Docs
Protocol Verified

Hybrid Routing Discovery

How we solve the sandbox URL paradox.

PRID: 1002
VERIFIED
2 min read

🏛️ Hybrid Content Discovery Strategy

Core Philosophy: In an uncertain runtime environment, locate content through a deterministic "registration dictionary".

1. Background: The Time-Travel Bug

In an SPA, when a link is clicked, the router's Loader executes immediately, but the browser's address bar (window.location) updates with a delay. If the Loader reads window.location, it gets the previous page's URL. This is why clicking in the Docs section might throw an error saying "Blog page not found".

2. Solution: Trust the Future

We must read the location parameter from the Loader's context. It represents the impending target state.

Logic Flow

mermaid
graph TD A[Loader Starts] --> B{Is it a Sandbox Environment?} B -- No --> C[Match directly using Router Params] B -- Yes --> D[Start Dictionary Scanner] D --> E[Read location from Router Context (Future State)] E --> F[Greedy match longest slug in registry] F --> G[Load corresponding Markdown data]

3. Greedy Matching Algorithm (Greedy Dictionary Matching Protocol)

To prevent path ambiguity (e.g., core vs. core/plan), we use a greedy matching logic:

  1. Get Dictionary: Extract all slugs from the generated manifest.
  2. Sort Descending: Sort by slug length in descending order (longest first).
  3. Prefix/Inclusion Check:
    typescript
    // Use the location passed by the router, it's the only source of truth const targetPath = location.pathname.toLowerCase(); const matched = allSlugs.sort((a,b) => b.length - a.length) .find(slug => targetPath.includes(slug));

4. Production vs. Development Balance

DimensionProduction Mode (PROD)Sandbox Rescue (SANDBOX)
TriggerStandard domain / Normal paramsBlob protocol / Param resolves to *
Data Sourceparamscontext.location
Match EfficiencyHigh (Direct Key lookup)Medium (String traversal)
SEO FriendlinessVery High (Standard)Low (Preview only)
Race Condition ImmunityN/AVery Strong (Ignores browser async update)

This strategy is the cornerstone of Instant Ship™'s ability to maintain a "plug-and-play" experience in AI Studio.

Authority Distribution

Share this technical artifact