Skip to content
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

Deduplicate route history #1273

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/router/src/history/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ impl<R: Routable> HistoryProvider<R> for MemoryHistory<R> {
}

fn push(&mut self, new: R) {
// don't push the same route twice
if self.current.to_string() == new.to_string() {
return;
}
let old = std::mem::replace(&mut self.current, new);
self.history.push(old);
self.future.clear();
Expand Down
10 changes: 10 additions & 0 deletions packages/router/src/history/web.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::{Arc, Mutex};

use gloo::{console::error, events::EventListener, render::AnimationFrame};

use wasm_bindgen::JsValue;
use web_sys::{window, History, ScrollRestoration, Window};

Expand Down Expand Up @@ -296,6 +297,11 @@ where
}

fn push(&mut self, state: R) {
use gloo_utils::format::JsValueSerdeExt;
if JsValue::from_serde(&state) != JsValue::from_serde(&self.current_route()) {
// don't push the same state twice
return;
}
let path = self.full_path(&state);

let state = self.create_state(state);
Expand Down Expand Up @@ -362,6 +368,10 @@ where
}

fn push(&mut self, state: R) {
if state.to_string() == self.current_route().to_string() {
// don't push the same state twice
return;
}
let path = self.full_path(&state);

let state: [f64; 2] = self.create_state(state);
Expand Down
Loading