Skip to content

Fix state legislative tracker deep links returning 404#912

Closed
SakshiKekre wants to merge 3 commits intomainfrom
fix/tracker-deep-links
Closed

Fix state legislative tracker deep links returning 404#912
SakshiKekre wants to merge 3 commits intomainfrom
fix/tracker-deep-links

Conversation

@SakshiKekre
Copy link
Copy Markdown
Collaborator

@SakshiKekre SakshiKekre commented Apr 3, 2026

Status: SUPERSEDED by #914

This PR attempted to fix tracker deep links by keeping the iframe and deriving the sub-path client-side. It had reliability issues:

  • Double-load when clicking links inside the tracker
  • Browser back button requires two presses
  • Copy-pasted deep links still load the tracker home page, not the deep link

PR #914 takes a simpler approach — switching from iframe to Vercel rewrite — which fixes deep links natively.


Original approach (for reference)

Added a catch-all route [countryId]/[slug]/[...rest]/page.tsx and modified AppClient to derive the sub-path from usePathname() client-side. The pre-built [slug] static page takes priority over the catch-all in Next.js, so the server-side subPath prop never reached the client. The client-side derivation partially worked but caused iframe reload cascades due to the postMessage URL sync mechanism.

Add beforeFiles rewrites so tracker deep links like
/us/state-legislative-tracker/MN/mn-hf4621 are served directly from
Modal instead of through an iframe. The tracker's client-side router
handles the path on page load.

Previously, only /_tracker/* asset paths were rewritten. The tracker
page itself was served via iframe through the [slug] route, which only
matches a single path segment — deep links with state/bill sub-paths
returned 404.

Fixes #911
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
policyengine-app-v2 Ready Ready Preview, Comment Apr 6, 2026 3:07am
policyengine-calculator Ready Ready Preview, Comment Apr 6, 2026 3:07am
policyengine-website Ready Ready Preview, Comment Apr 6, 2026 3:07am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
policyengine-calculator-next Skipped Skipped Apr 6, 2026 3:07am

Request Review

Replace the rewrite approach with a catch-all route that preserves the
iframe wrapper (header/footer). The tracker app doesn't have its own
header, so serving it directly via rewrite would lose navigation chrome.

Changes:
- Add [countryId]/[slug]/[...rest]/page.tsx catch-all route
- Add subPath prop to AppClient, appended to iframe src URL
- Revert the beforeFiles rewrite from previous commit

When someone pastes /us/state-legislative-tracker/MN/mn-hf4621, the
catch-all matches, passes subPath="/MN/mn-hf4621" to AppClient, which
appends it to the iframe src. The tracker SPA loads at that path and
its client-side router shows the right bill.
The pre-built [slug] static page takes priority over the [..rest]
catch-all, so the server-side subPath prop never arrives. Instead,
derive the sub-path from usePathname() on the client — this always
returns the full browser URL regardless of which route matched.
@SakshiKekre
Copy link
Copy Markdown
Collaborator Author

This approach (catch-all route + client-side sub-path derivation) had reliability issues on preview testing — double-loads, broken back button, and deep links still not resolving correctly. The root cause is that the iframe + postMessage + replaceState architecture fundamentally creates URLs the server can't serve.

PR #914 takes a different approach: switches the tracker from iframe to a Vercel rewrite, matching how all other external apps (KYPA, WATCA, Oregon Kicker, etc.) are already served. Deep links work natively because the tracker SPA loads for any path. #914 should be merged instead of this PR.

Keeping this PR open for reference in case we need to revisit the iframe approach.

@SakshiKekre SakshiKekre closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant