Skip to content

fix(embed-shims): soft-navigate in next/navigation router fallback#1448

Merged
pavlo-flamingo merged 3 commits into
mainfrom
hotfix/embed-shim-router-soft-navigate
Jul 14, 2026
Merged

fix(embed-shims): soft-navigate in next/navigation router fallback#1448
pavlo-flamingo merged 3 commits into
mainfrom
hotfix/embed-shim-router-soft-navigate

Conversation

@pavlo-flamingo

@pavlo-flamingo pavlo-flamingo commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Проблема

В шиме src/embed-shims/next-navigation.tsx незарегистрированный фолбэк useRouter().push/replace использовал window.location.assign/replace. Из-за этого same-origin запись ?search= (например, из useApiParams) вызывала полную перезагрузку документа вместо SPA-навигации — в том числе когда реальный роутер не зарегистрирован либо регистрация попала в другой инстанс модуля (дубликат библиотеки / ESM-CJS dual package).

Решение

softNavigate() роутит same-origin push/replace через History API (pushState/replaceState + синтетический popstate), поэтому запись query-параметров остаётся SPA и подписчики этого файла (usePathname/useSearchParams) ре-рендерятся. Cross-origin и malformed href по-прежнему уходят в реальную window.location-навигацию — единственно корректное поведение там.

Тесты

Добавлены регрессионные тесты (__tests__/next-navigation.test.ts), покрывающие фолбэк push/replace, cross-origin и malformed фолбэки, back/forward и путь с зарегистрированным host-роутером. Все 6 проходят.

Summary by CodeRabbit

  • Bug Fixes
    • Improved embedded navigation so same-origin route changes update the page without a full reload.
    • Ensured pathname and search parameter displays refresh after programmatic navigation.
    • Preserved standard navigation for cross-origin and invalid destinations.
    • Maintained host router behavior when available, including browser back and forward navigation.

The unregistered `useRouter().push/replace` fallback used
`window.location.assign/replace`, so a same-origin `?search=` write from
`useApiParams` hard-reloaded the document. Route push/replace through the
History API (`pushState`/`replaceState` + synthetic `popstate`) for
same-origin URLs so query-param writes stay SPA; cross-origin/malformed
hrefs still fall back to a real `window.location` navigation.

Add regression tests covering fallback push/replace, cross-origin and
malformed fallbacks, back/forward, and the registered host-router path.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@pavlo-flamingo, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 39 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b05ff9a4-0899-43fa-8af1-8ab08eab6b69

📥 Commits

Reviewing files that changed from the base of the PR and between 0589a52 and bcdf633.

📒 Files selected for processing (2)
  • openframe-frontend-core/src/embed-shims/__tests__/next-navigation.test.ts
  • openframe-frontend-core/src/embed-shims/next-navigation.tsx
📝 Walkthrough

Walkthrough

The next/navigation shim now uses History API navigation for same-origin fallback routes, dispatches synthetic popstate events, preserves hard navigation for cross-origin or malformed URLs, and adds tests for fallback and registered-router behavior.

Changes

Navigation fallback behavior

Layer / File(s) Summary
History-based fallback navigation
openframe-frontend-core/src/embed-shims/next-navigation.tsx
Same-origin push and replace calls use history.pushState or history.replaceState followed by a synthetic popstate; cross-origin or malformed targets use window.location.assign. Documentation reflects the updated behavior.
Router behavior coverage
openframe-frontend-core/src/embed-shims/__tests__/next-navigation.test.ts
Tests isolate shim state, verify fallback navigation and History methods, cover hard-navigation cases, and confirm registered host-router delegation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant NextNavigationShim
  participant HistoryAPI
  participant Window
  Application->>NextNavigationShim: call router.push or router.replace
  NextNavigationShim->>HistoryAPI: update same-origin URL
  NextNavigationShim->>Window: dispatch synthetic popstate
  NextNavigationShim->>Window: assign cross-origin or malformed URL
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: soft-navigation behavior in the next/navigation embed-shim router fallback.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/embed-shim-router-soft-navigate

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openframe-frontend-core/src/embed-shims/next-navigation.tsx`:
- Around line 102-134: Update softNavigate so cross-origin and malformed href
fallbacks use window.location.replace when mode is 'replace' and
window.location.assign otherwise, preserving the existing same-origin behavior.
Update the next-navigation tests to expect replace for cross-origin replace
calls and add coverage for malformed hrefs invoked through replace().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b3316da-5bae-4234-90c7-35c5edea11a7

📥 Commits

Reviewing files that changed from the base of the PR and between d56cf5b and 0589a52.

📒 Files selected for processing (2)
  • openframe-frontend-core/src/embed-shims/__tests__/next-navigation.test.ts
  • openframe-frontend-core/src/embed-shims/next-navigation.tsx

Comment thread openframe-frontend-core/src/embed-shims/next-navigation.tsx
…n fallback

Cross-origin and malformed hrefs ignored the push/replace mode and always
called window.location.assign, so useRouter().replace() left a back-button
entry — contradicting the replace contract. Route replace-mode fallbacks
through window.location.replace. Add test coverage for cross-origin push,
and malformed href via replace().
@pavlo-flamingo pavlo-flamingo enabled auto-merge (squash) July 14, 2026 19:47
@pavlo-flamingo pavlo-flamingo merged commit 43c5cc8 into main Jul 14, 2026
7 checks passed
@pavlo-flamingo pavlo-flamingo deleted the hotfix/embed-shim-router-soft-navigate branch July 14, 2026 20:02
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.

2 participants