Skip to content

Commit

Permalink
Merge pull request #2203 from leptos-rs/2201
Browse files Browse the repository at this point in the history
fix: routing regressions caused by `trailing_slash` support
  • Loading branch information
gbj authored Jan 19, 2024
2 parents 1d47722 + 5cacb57 commit dd5a0ae
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 831 deletions.
4 changes: 4 additions & 0 deletions examples/router/e2e/tests/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ test.describe("Test Router example", () => {
await page.goto("/");
});

test("Starts on correct home page", async({ page }) => {
await expect(page.getByText("Select a contact.")).toBeVisible();
});

const links = [
{ label: "Bill Smith", url: "/0" },
{ label: "Tim Jones", url: "/1" },
Expand Down
3 changes: 1 addition & 2 deletions examples/ssr_modes/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ use thiserror::Error;
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
let fallback = || view! { "Page not found." }.into_view();

view! {
<Stylesheet id="leptos" href="/pkg/ssr_modes.css"/>
<Title text="Welcome to Leptos"/>

<Router fallback>
<Router>
<main>
<Routes>
// We’ll load the home page with out-of-order streaming and <Suspense/>
Expand Down
3 changes: 1 addition & 2 deletions examples/ssr_modes_axum/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ use thiserror::Error;
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
let fallback = || view! { "Page not found." }.into_view();

view! {
<Stylesheet id="leptos" href="/pkg/ssr_modes.css"/>
<Title text="Welcome to Leptos"/>

<Router fallback>
<Router>
<main>
<Routes>
// We’ll load the home page with out-of-order streaming and <Suspense/>
Expand Down
1 change: 1 addition & 0 deletions examples/todo_app_sqlite/src/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cfg_if! {
}
}

/// Server functions can be given doc comments.
#[server(GetTodos, "/api")]
pub async fn get_todos() -> Result<Vec<Todo>, ServerFnError> {
// this is just an example of how to access server context injected in the handlers
Expand Down
148 changes: 0 additions & 148 deletions integrations/actix/tests/extract_routes.rs

This file was deleted.

4 changes: 2 additions & 2 deletions leptos_dom/src/hydration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod hydrate_only {
}
});

pub static IS_HYDRATING: Cell<bool> = Cell::new(true);
pub static IS_HYDRATING: Cell<bool> = const { Cell::new(true) };
}

#[allow(unused)]
Expand Down Expand Up @@ -133,7 +133,7 @@ mod tests {
}
}

thread_local!(static ID: RefCell<HydrationKey> = RefCell::new(HydrationKey { outlet: 0, fragment: 0, error: 0, id: 0 }));
thread_local!(static ID: RefCell<HydrationKey> = const {RefCell::new(HydrationKey { outlet: 0, fragment: 0, error: 0, id: 0 })});

/// Control and utility methods for hydration.
pub struct HydrationCtx;
Expand Down
4 changes: 2 additions & 2 deletions leptos_dom/src/macro_helpers/tracing_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ fn match_primitive() {
assert_eq!(prop, r#"{"name": "test", "value": -1}"#);

// f64
let test = 3.14;
let test = 3.25;
let prop = (&&Match {
name: stringify! {test},
value: std::cell::Cell::new(Some(&test)),
})
.spez();
assert_eq!(prop, r#"{"name": "test", "value": 3.14}"#);
assert_eq!(prop, r#"{"name": "test", "value": 3.25}"#);

// bool
let test = true;
Expand Down
2 changes: 1 addition & 1 deletion leptos_reactive/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cfg_if::cfg_if! {
use std::cell::Cell;

thread_local! {
static IS_SPECIAL_ZONE: Cell<bool> = Cell::new(false);
static IS_SPECIAL_ZONE: Cell<bool> = const { Cell::new(false) };
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion leptos_reactive/src/hydration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl Default for SharedContext {

#[cfg(feature = "experimental-islands")]
thread_local! {
pub static NO_HYDRATE: Cell<bool> = Cell::new(true);
pub static NO_HYDRATE: Cell<bool> = const { Cell::new(true) };
}

#[cfg(feature = "experimental-islands")]
Expand Down
2 changes: 1 addition & 1 deletion leptos_reactive/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ impl<S, T> UnserializableResource for ResourceState<S, T> {
}

thread_local! {
static SUPPRESS_RESOURCE_LOAD: Cell<bool> = Cell::new(false);
static SUPPRESS_RESOURCE_LOAD: Cell<bool> = const { Cell::new(false) };
}

#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion leptos_reactive/src/stored_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<T> StoredValue<T> {
with_runtime(|runtime| {
let n = {
let values = runtime.stored_values.borrow();
values.get(self.id).map(Rc::clone)
values.get(self.id).cloned()
};

if let Some(n) = n {
Expand Down
41 changes: 8 additions & 33 deletions router/src/components/route.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
matching::{resolve_path, PathMatch, RouteDefinition, RouteMatch},
ParamsMap, RouterContext, SsrMode, StaticData, StaticMode, StaticParamsMap,
TrailingSlash,
};
use leptos::{leptos_dom::Transparent, *};
use std::{
Expand All @@ -15,17 +14,7 @@ use std::{
};

thread_local! {
static ROUTE_ID: Cell<usize> = Cell::new(0);
}

// RouteDefinition.id is `pub` and required to be unique.
// Should we make this public so users can generate unique IDs?
pub(in crate::components) fn new_route_id() -> usize {
ROUTE_ID.with(|id| {
let next = id.get() + 1;
id.set(next);
next
})
static ROUTE_ID: Cell<usize> = const { Cell::new(0) };
}

/// Represents an HTTP method that can be handled by this route.
Expand Down Expand Up @@ -76,11 +65,6 @@ pub fn Route<E, F, P>(
/// accessed with [`use_route_data`](crate::use_route_data).
#[prop(optional, into)]
data: Option<Loader>,
/// How this route should handle trailing slashes in its path.
/// Overrides any setting applied to [`crate::components::Router`].
/// Serves as a default for any inner Routes.
#[prop(optional)]
trailing_slash: Option<TrailingSlash>,
/// `children` may be empty or include nested routes.
#[prop(optional)]
children: Option<Children>,
Expand All @@ -99,7 +83,6 @@ where
data,
None,
None,
trailing_slash,
)
}

Expand Down Expand Up @@ -132,11 +115,6 @@ pub fn ProtectedRoute<P, E, F, C>(
/// accessed with [`use_route_data`](crate::use_route_data).
#[prop(optional, into)]
data: Option<Loader>,
/// How this route should handle trailing slashes in its path.
/// Overrides any setting applied to [`crate::components::Router`].
/// Serves as a default for any inner Routes.
#[prop(optional)]
trailing_slash: Option<TrailingSlash>,
/// `children` may be empty or include nested routes.
#[prop(optional)]
children: Option<Children>,
Expand Down Expand Up @@ -165,7 +143,6 @@ where
data,
None,
None,
trailing_slash,
)
}

Expand Down Expand Up @@ -194,11 +171,6 @@ pub fn StaticRoute<E, F, P, S>(
/// accessed with [`use_route_data`](crate::use_route_data).
#[prop(optional, into)]
data: Option<Loader>,
/// How this route should handle trailing slashes in its path.
/// Overrides any setting applied to [`crate::components::Router`].
/// Serves as a default for any inner Routes.
#[prop(optional)]
trailing_slash: Option<TrailingSlash>,
/// `children` may be empty or include nested routes.
#[prop(optional)]
children: Option<Children>,
Expand All @@ -221,7 +193,6 @@ where
data,
Some(mode),
Some(Arc::new(static_params)),
trailing_slash,
)
}

Expand All @@ -239,7 +210,6 @@ pub(crate) fn define_route(
data: Option<Loader>,
static_mode: Option<StaticMode>,
static_params: Option<StaticData>,
trailing_slash: Option<TrailingSlash>,
) -> RouteDefinition {
let children = children
.map(|children| {
Expand All @@ -256,8 +226,14 @@ pub(crate) fn define_route(
})
.unwrap_or_default();

let id = ROUTE_ID.with(|id| {
let next = id.get() + 1;
id.set(next);
next
});

RouteDefinition {
id: new_route_id(),
id,
path,
children,
view,
Expand All @@ -266,7 +242,6 @@ pub(crate) fn define_route(
data,
static_mode,
static_params,
trailing_slash,
}
}

Expand Down
Loading

0 comments on commit dd5a0ae

Please sign in to comment.