Add more trace messages to the RouterService code

I was trying to debug some issues with my routes and this additional tracing
was quite helpful.
This commit is contained in:
Dave Rolsky committed 2022-01-13 12:21:06 -06:00
1 parent d367e0f89f
commit 3a5b417ad1
2 files changed
+16 -2

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element {
Some(ctx) => ctx.total_route.to_string(), Some(ctx) => ctx.total_route.to_string(),
None => cx.props.to.to_string(), None => cx.props.to.to_string(),
}; };
log::trace!("total route for {} is {}", cx.props.to, total_route);
// provide our route context // provide our route context
let route_context = cx.provide_context(RouteContext { let route_context = cx.provide_context(RouteContext {
+15 -2
View File
@@ -46,8 +46,8 @@ impl RouterService {
let listener = history.listen(move || { let listener = history.listen(move || {
_root_found.set(false); _root_found.set(false);
// checking if the route is valid is cheap, so we do it // checking if the route is valid is cheap, so we do it
for (slot, _) in _slots.borrow_mut().iter().rev() { for (slot, root) in _slots.borrow_mut().iter().rev() {
log::trace!("regenerating slot {:?}", slot); log::trace!("regenerating slot {:?} for root '{}'", slot, root);
regen(*slot); regen(*slot);
} }
}); });
@@ -68,20 +68,25 @@ impl RouterService {
} }
pub fn push_route(&self, route: &str) { pub fn push_route(&self, route: &str) {
log::trace!("Pushing route: {}", route);
self.history.borrow_mut().push(route); self.history.borrow_mut().push(route);
} }
pub fn register_total_route(&self, route: String, scope: ScopeId, fallback: bool) { pub fn register_total_route(&self, route: String, scope: ScopeId, fallback: bool) {
log::trace!("Registered route '{}' with scope id {:?}", route, scope);
self.slots.borrow_mut().push((scope, route)); self.slots.borrow_mut().push((scope, route));
} }
pub fn should_render(&self, scope: ScopeId) -> bool { pub fn should_render(&self, scope: ScopeId) -> bool {
log::trace!("Should render scope id {:?}?", scope);
if self.root_found.get() { if self.root_found.get() {
log::trace!(" no - because root_found is true");
return false; return false;
} }
let location = self.history.borrow().location(); let location = self.history.borrow().location();
let path = location.path(); let path = location.path();
log::trace!(" current path is '{}'", path);
let roots = self.slots.borrow(); let roots = self.slots.borrow();
@@ -90,14 +95,22 @@ impl RouterService {
// fallback logic // fallback logic
match root { match root {
Some((_id, route)) => { Some((_id, route)) => {
log::trace!(
" matched given scope id {:?} with route root '{}'",
scope,
route,
);
if route == path { if route == path {
log::trace!(" and it matches the current path '{}'", path);
self.root_found.set(true); self.root_found.set(true);
true true
} else { } else {
if route == "" { if route == "" {
log::trace!(" and the route is the root, so we will use that without a better match");
self.root_found.set(true); self.root_found.set(true);
true true
} else { } else {
log::trace!(" and the route '{}' is not the root nor does it match the current path", route);
false false
} }
} }