-
Notifications
You must be signed in to change notification settings - Fork 13.3k
fix: disable navbar back and forward buttons at history boundaries #38947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
fe6d953
67e536f
bd9f4a8
af9ae93
99f83fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,14 @@ export class Router implements RouterContextValue { | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private readonly page = new Page(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private historyIndex = 0; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private historyMaxIndex = 0; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private pendingHistoryDelta = 0; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private pendingPush = false; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||||||||||||||||
| this.registerRoute('*', { id: 'not-found' }); | ||||||||||||||||||||||||||||||||||||||||
| this.updateCallbacks(); | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -166,6 +174,16 @@ export class Router implements RouterContextValue { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private refresh() { | ||||||||||||||||||||||||||||||||||||||||
| if (this.pendingHistoryDelta !== 0) { | ||||||||||||||||||||||||||||||||||||||||
| this.historyIndex += this.pendingHistoryDelta; | ||||||||||||||||||||||||||||||||||||||||
| this.pendingHistoryDelta = 0; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| if (this.pendingPush) { | ||||||||||||||||||||||||||||||||||||||||
| this.historyIndex += 1; | ||||||||||||||||||||||||||||||||||||||||
| this.historyMaxIndex = this.historyIndex; | ||||||||||||||||||||||||||||||||||||||||
| this.pendingPush = false; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+177
to
+185
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If 🛡️ Proposed fix: clamp after applying delta if (this.pendingHistoryDelta !== 0) {
this.historyIndex += this.pendingHistoryDelta;
+ this.historyIndex = Math.max(0, Math.min(this.historyIndex, this.historyMaxIndex));
this.pendingHistoryDelta = 0;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if (!this.current?.route) return; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const currentContext = this.current; | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -273,6 +291,7 @@ export class Router implements RouterContextValue { | |||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||||||||||||
| if (typeof toOrDelta === 'number') { | ||||||||||||||||||||||||||||||||||||||||
| this.pendingHistoryDelta = toOrDelta; | ||||||||||||||||||||||||||||||||||||||||
| history.go(toOrDelta); | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
schourasia750 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -283,6 +302,7 @@ export class Router implements RouterContextValue { | |||||||||||||||||||||||||||||||||||||||
| if (options?.replace) { | ||||||||||||||||||||||||||||||||||||||||
| history.replaceState(state, '', path); | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| this.pendingPush = true; | ||||||||||||||||||||||||||||||||||||||||
| history.pushState(state, '', path); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -315,6 +335,10 @@ export class Router implements RouterContextValue { | |||||||||||||||||||||||||||||||||||||||
| readonly getRoomRoute = (roomType: RoomType, routeData: RoomRouteData) => { | ||||||||||||||||||||||||||||||||||||||||
| return { path: roomCoordinator.getRouteLink(roomType, routeData) || '/' }; | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| readonly getCanGoBack = (): boolean => this.historyIndex > 0; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| readonly getCanGoForward = (): boolean => this.historyIndex < this.historyMaxIndex; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| type RouteOptions = { | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.