Skip to content

Add replace support#96

Draft
iObject wants to merge 11 commits into
masterfrom
95-add-replace-support
Draft

Add replace support#96
iObject wants to merge 11 commits into
masterfrom
95-add-replace-support

Conversation

@iObject

@iObject iObject commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds “replace” navigation semantics to the sgRouter so callers can replace the current history entry (and corresponding view) rather than pushing a new one, along with test coverage for the new option.

Changes:

  • Introduce { replace: true } option handling in Router._navigateTo, including new fromReplaceState navigation-state flag.
  • Update history stack logic in showView to replace the last entry when fromReplaceState is set.
  • Add a new describe("replace") test block validating history behavior, view destruction, mid-stack replacement, event emission, and named-route support.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/components/Router.bs Implements replace option and updates view/history management via new fromReplaceState flag.
src/source/router.spec.bs Adds tests covering the new replace navigation behavior.
Comments suppressed due to low confidence (1)

src/components/Router.bs:868

  • The fromReplaceState history-update branch bypasses the clearStackOnResolve history reset logic. If a route has clearStackOnResolve=true and navigation is invoked with { replace: true }, views can be cleared but __router_historyStack won’t be, leaving stale entries and breaking goBack/popTo. Consider making clearStackOnResolve override/ignore replace, or clearing the stack before applying replace semantics.
                    if context.view.route.routeConfig.clearStackOnResolve then
                        m.__router_historyStack = []
                    end if

                    if context.view.route.navigationState.fromPushState then

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/Router.bs
Comment thread src/components/Router.bs Outdated
Comment thread src/source/router.spec.bs
@iObject iObject requested a review from Copilot March 16, 2026 14:56
@iObject iObject added the create-package create a temporary npm package on every commit label Mar 16, 2026
@rokucommunity-bot

Copy link
Copy Markdown
Contributor

Hey there! I just built a new temporary npm package based on 3eb5079. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316150414.tgz

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds “replace navigation” support to the sgRouter so callers can navigate forward while replacing the current history entry (similar to history.replaceState), and introduces tests to validate replace semantics across history/view-stack behavior.

Changes:

  • Add replace option handling to Router navigation, including new fromReplaceState navigation state flag and history-stack replacement logic.
  • Ensure replace closes the currently active view (when not clearStackOnResolve) and updates router state events consistently.
  • Add a new replace test suite covering history replacement, view destruction, named routes, and interaction with clearStackOnResolve.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/components/Router.bs Implements replace option, sets fromReplaceState, adjusts view removal behavior, and replaces the last history entry on navigation.
src/source/interfaces.bs Extends NavigationState with fromReplaceState to represent replace-style forward navigation.
src/source/router.spec.bs Adds coverage for replace navigation behavior (history, view stack, events, named routes, clear-stack precedence).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/Router.bs Outdated
@rokucommunity-bot

Copy link
Copy Markdown
Contributor

Hey there! I just built a new temporary npm package based on c004f50. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316152424.tgz

@rokucommunity-bot

Copy link
Copy Markdown
Contributor

Hey there! I just built a new temporary npm package based on 705aa78. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316162539.tgz

@rokucommunity-bot

Copy link
Copy Markdown
Contributor

Hey there! I just built a new temporary npm package based on 003fd41. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316185622.tgz

@rokucommunity-bot

Copy link
Copy Markdown
Contributor

Hey there! I just built a new temporary npm package based on 2c957f1. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316190233.tgz

@iObject iObject marked this pull request as ready for review March 16, 2026 19:11
@rokucommunity-bot

Copy link
Copy Markdown
Contributor

Hey there! I just built a new temporary npm package based on b9d78ce. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260317115805.tgz

@iObject iObject added the enhancement New feature or request label Mar 17, 2026
@rokucommunity-bot

Copy link
Copy Markdown
Contributor

Hey there! I just built a new temporary npm package based on b9d78ce. You can download it here or install it by running the following command:

npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260317120038.tgz

Comment thread src/components/Router.bs
end if

viewsToRemoveOnResolve = []
forceCloseViews = []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might need to rethink this? I think these might bypass the keepalive stuff, but probably shouldn't.

@iObject iObject marked this pull request as draft March 17, 2026 19:16
Comment thread src/source/interfaces.bs
@@ -27,6 +27,7 @@ namespace sgRouter
interface NavigationState
fromPushState as Boolean ' normal forward navigation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should likely set this as part of this PR too (since replace is equivalent to a .pop() and .push())

Base automatically changed from 92-add-popto-support to master April 30, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-package create a temporary npm package on every commit enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants