Skip to content

Commit

Permalink
feat: upgraded to sycamore v0.7.0
Browse files Browse the repository at this point in the history
Hydration has been feature-gated and disabled by default for now due to
a bug where interpolated variables are duplicated. This results in a
full page flicker for now until this error is fixed.

BREAKING CHANGE: upgraded to Sycamore v0.7.0 (see [their changelog](https://github.com/sycamore-rs/sycamore/blob/master/CHANGELOG.md))
  • Loading branch information
arctic-hen7 committed Dec 13, 2021
1 parent d178f5a commit 3989241
Show file tree
Hide file tree
Showing 45 changed files with 227 additions and 190 deletions.
4 changes: 2 additions & 2 deletions examples/basic/.perseus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ edition = "2018"
app = { package = "perseus-example-basic", path = "../" }

perseus = { path = "../../../packages/perseus" }
sycamore = { version = "0.6", features = ["ssr"] }
sycamore-router = "0.6"
sycamore = { version = "0.7", features = ["ssr"] }
sycamore-router = "0.7"
web-sys = { version = "0.3", features = ["Event", "Headers", "Request", "RequestInit", "RequestMode", "Response", "ReadableStream", "Window"] }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
Expand Down
22 changes: 11 additions & 11 deletions examples/basic/.perseus/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use perseus::{
internal::i18n::Locales,
stores::ImmutableStore,
templates::{ArcTemplateMap, TemplateMap},
ErrorPages, GenericNode, PluginAction, Plugins,
ErrorPages, Html, PluginAction, Plugins,
};
use std::{collections::HashMap, rc::Rc, sync::Arc};

Expand All @@ -17,7 +17,7 @@ pub use app::{get_mutable_store, get_translations_manager};
// pub fn get_mutable_store() -> impl MutableStore {
// todo!()
// }
pub fn get_immutable_store<G: GenericNode>(plugins: &Plugins<G>) -> ImmutableStore {
pub fn get_immutable_store<G: Html>(plugins: &Plugins<G>) -> ImmutableStore {
let immutable_store = app::get_immutable_store();
plugins
.control_actions
Expand All @@ -26,7 +26,7 @@ pub fn get_immutable_store<G: GenericNode>(plugins: &Plugins<G>) -> ImmutableSto
.run(immutable_store.clone(), plugins.get_plugin_data())
.unwrap_or(immutable_store)
}
pub fn get_app_root<G: GenericNode>(plugins: &Plugins<G>) -> String {
pub fn get_app_root<G: Html>(plugins: &Plugins<G>) -> String {
plugins
.control_actions
.settings_actions
Expand All @@ -37,7 +37,7 @@ pub fn get_app_root<G: GenericNode>(plugins: &Plugins<G>) -> String {
// pub async fn get_translations_manager() -> impl TranslationsManager {
// todo!()
// }
pub fn get_locales<G: GenericNode>(plugins: &Plugins<G>) -> Locales {
pub fn get_locales<G: Html>(plugins: &Plugins<G>) -> Locales {
let locales = app::get_locales();
plugins
.control_actions
Expand All @@ -47,7 +47,7 @@ pub fn get_locales<G: GenericNode>(plugins: &Plugins<G>) -> Locales {
.unwrap_or(locales)
}
// This also performs rescoping and security checks so that we don't include anything outside the project root
pub fn get_static_aliases<G: GenericNode>(plugins: &Plugins<G>) -> HashMap<String, String> {
pub fn get_static_aliases<G: Html>(plugins: &Plugins<G>) -> HashMap<String, String> {
let mut static_aliases = app::get_static_aliases();
// This will return a map of plugin name to another map of static aliases that that plugin produced
let extra_static_aliases = plugins
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn get_static_aliases<G: GenericNode>(plugins: &Plugins<G>) -> HashMap<Strin
scoped_static_aliases
}
// This doesn't take plugins because that would actually increase allocation and indirection on the server
pub fn get_templates_map<G: GenericNode>(plugins: &Plugins<G>) -> TemplateMap<G> {
pub fn get_templates_map<G: Html>(plugins: &Plugins<G>) -> TemplateMap<G> {
let mut templates = app::get_templates_map::<G>();
// This will return a map of plugin name to a vector of templates to add
let extra_templates = plugins
Expand All @@ -117,7 +117,7 @@ pub fn get_templates_map<G: GenericNode>(plugins: &Plugins<G>) -> TemplateMap<G>

templates
}
pub fn get_templates_map_atomic<G: GenericNode>(plugins: &Plugins<G>) -> ArcTemplateMap<G> {
pub fn get_templates_map_atomic<G: Html>(plugins: &Plugins<G>) -> ArcTemplateMap<G> {
let mut templates = app::get_templates_map_atomic::<G>();
// This will return a map of plugin name to a vector of templates to add
let extra_templates = plugins
Expand All @@ -134,7 +134,7 @@ pub fn get_templates_map_atomic<G: GenericNode>(plugins: &Plugins<G>) -> ArcTemp

templates
}
pub fn get_error_pages<G: GenericNode>(plugins: &Plugins<G>) -> ErrorPages<G> {
pub fn get_error_pages<G: Html>(plugins: &Plugins<G>) -> ErrorPages<G> {
let mut error_pages = app::get_error_pages::<G>();
// This will return a map of plugin name to a map of status codes to error pages
let extra_error_pages = plugins
Expand All @@ -153,15 +153,15 @@ pub fn get_error_pages<G: GenericNode>(plugins: &Plugins<G>) -> ErrorPages<G> {

// We provide alternatives for `get_templates_map` and `get_error_pages` that get their own plugins
// This avoids major allocation/sync problems on the server
pub fn get_templates_map_contained<G: GenericNode>() -> TemplateMap<G> {
pub fn get_templates_map_contained<G: Html>() -> TemplateMap<G> {
let plugins = get_plugins::<G>();
get_templates_map(&plugins)
}
pub fn get_templates_map_atomic_contained<G: GenericNode>() -> ArcTemplateMap<G> {
pub fn get_templates_map_atomic_contained<G: Html>() -> ArcTemplateMap<G> {
let plugins = get_plugins::<G>();
get_templates_map_atomic(&plugins)
}
pub fn get_error_pages_contained<G: GenericNode>() -> ErrorPages<G> {
pub fn get_error_pages_contained<G: Html>() -> ErrorPages<G> {
let plugins = get_plugins::<G>();
get_error_pages(&plugins)
}
13 changes: 7 additions & 6 deletions examples/basic/.perseus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use perseus::{
shell::{app_shell, get_initial_state, get_render_cfg, InitialState},
},
plugins::PluginAction,
templates::TemplateNodeType,
DomNode,
};
use std::cell::RefCell;
use std::rc::Rc;
use sycamore::prelude::{cloned, create_effect, template, NodeRef, StateHandle};
use sycamore::prelude::{cloned, create_effect, view, NodeRef, ReadSignal};
use sycamore_router::{HistoryIntegration, Router, RouterProps};
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};

Expand Down Expand Up @@ -77,8 +78,8 @@ pub fn run() -> Result<(), JsValue> {

sycamore::render_to(
move || {
template! {
Router(RouterProps::new(HistoryIntegration::new(), move |route: StateHandle<AppRoute<DomNode>>| {
view! {
Router(RouterProps::new(HistoryIntegration::new(), move |route: ReadSignal<AppRoute<TemplateNodeType>>| {
create_effect(cloned!((container_rx) => move || {
// Sycamore's reactivity is broken by a future, so we need to explicitly add the route to the reactive dependencies here
// We do need the future though (otherwise `container_rx` doesn't link to anything until it's too late)
Expand Down Expand Up @@ -122,9 +123,9 @@ pub fn run() -> Result<(), JsValue> {
initial_container.set_attribute("style", "display: none;").unwrap();
// Hydrate the error pages
// Right now, we don't provide translators to any error pages that have come from the server
error_pages.hydrate_page(&url, &status, &err, None, &container_rx_elem);
error_pages.render_page(&url, &status, &err, None, &container_rx_elem);
} else {
error_pages.hydrate_page("", &404, "not found", None, &container_rx_elem);
error_pages.render_page("", &404, "not found", None, &container_rx_elem);
}
},
};
Expand All @@ -133,7 +134,7 @@ pub fn run() -> Result<(), JsValue> {
// This template is reactive, and will be updated as necessary
// However, the server has already rendered initial load content elsewhere, so we move that into here as well in the app shell
// The main reason for this is that the router only intercepts click events from its children
template! {
view! {
div(id="__perseus_content_rx", class="__perseus_content", ref=container_rx) {}
}
}))
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"

[dependencies]
perseus = { path = "../../packages/perseus" }
sycamore = "0.6"
sycamore = "0.7"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/Cargo.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2018"

[dependencies]
perseus = "0.3.0-beta.21"
sycamore = "0.6"
sycamore = "0.7"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
10 changes: 5 additions & 5 deletions examples/basic/src/error_pages.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use perseus::{ErrorPages, GenericNode};
use sycamore::template;
use perseus::{ErrorPages, Html};
use sycamore::view;

pub fn get_error_pages<G: GenericNode>() -> ErrorPages<G> {
pub fn get_error_pages<G: Html>() -> ErrorPages<G> {
let mut error_pages = ErrorPages::new(|url, status, err, _| {
template! {
view! {
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
}
});
error_pages.add_page(404, |_, _, _, _| {
template! {
view! {
p { "Page not found." }
}
});
Expand Down
12 changes: 6 additions & 6 deletions examples/basic/src/templates/about.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use perseus::Template;
use sycamore::prelude::{component, template, GenericNode, SsrNode, Template as SycamoreTemplate};
use sycamore::prelude::{component, view, Html, SsrNode, View};

#[perseus::template(AboutPage)]
#[component(AboutPage<G>)]
pub fn about_page() -> SycamoreTemplate<G> {
template! {
pub fn about_page() -> View<G> {
view! {
p { "About." }
}
}

#[perseus::head]
pub fn head() -> SycamoreTemplate<SsrNode> {
template! {
pub fn head() -> View<SsrNode> {
view! {
title { "About Page | Perseus Example – Basic" }
}
}

pub fn get_template<G: GenericNode>() -> Template<G> {
pub fn get_template<G: Html>() -> Template<G> {
Template::new("about").template(about_page).head(head)
}
14 changes: 7 additions & 7 deletions examples/basic/src/templates/index.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use perseus::{
http::header::{HeaderMap, HeaderName},
GenericNode, RenderFnResultWithCause, SsrNode, Template,
Html, RenderFnResultWithCause, SsrNode, Template,
};
use serde::{Deserialize, Serialize};
use sycamore::prelude::{component, template, Template as SycamoreTemplate};
use sycamore::prelude::{component, view, View};

#[derive(Serialize, Deserialize, Debug)]
pub struct IndexPageProps {
Expand All @@ -12,14 +12,14 @@ pub struct IndexPageProps {

#[perseus::template(IndexPage)]
#[component(IndexPage<G>)]
pub fn index_page(props: IndexPageProps) -> SycamoreTemplate<G> {
template! {
pub fn index_page(props: IndexPageProps) -> View<G> {
view! {
p {(props.greeting)}
a(href = "about", id = "about-link") { "About!" }
}
}

pub fn get_template<G: GenericNode>() -> Template<G> {
pub fn get_template<G: Html>() -> Template<G> {
Template::new("index")
.build_state_fn(get_build_props)
.template(index_page)
Expand All @@ -28,8 +28,8 @@ pub fn get_template<G: GenericNode>() -> Template<G> {
}

#[perseus::head]
pub fn head(_props: IndexPageProps) -> SycamoreTemplate<SsrNode> {
template! {
pub fn head(_props: IndexPageProps) -> View<SsrNode> {
view! {
title { "Index Page | Perseus Example – Basic" }
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/i18n/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ edition = "2018"
# Perseus itself, which we (amazingly) need for a Perseus app
perseus = { path = "../../packages/perseus", features = [ "translator-fluent" ] }
# Sycamore, the library Perseus depends on for lower-leve reactivity primitivity
sycamore = { version = "0.6", features = ["ssr"] }
sycamore-router = "0.6"
sycamore = { version = "0.7", features = ["ssr"] }
sycamore-router = "0.7"
# Serde, which lets you work with representations of data, like JSON
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
12 changes: 6 additions & 6 deletions examples/i18n/src/error_pages.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use perseus::{ErrorPages, GenericNode};
use sycamore::template;
use perseus::{ErrorPages, Html};
use sycamore::view;

pub fn get_error_pages<G: GenericNode>() -> ErrorPages<G> {
pub fn get_error_pages<G: Html>() -> ErrorPages<G> {
let mut error_pages = ErrorPages::new(|_, _, err, _| {
template! {
view! {
p { (format!("Another error occurred: '{}'.", err)) }
}
});
error_pages.add_page(404, |_, _, _, _| {
template! {
view! {
p { "Page not found." }
}
});
error_pages.add_page(400, |_, _, _, _| {
template! {
view! {
p { "Client error occurred..." }
}
});
Expand Down
8 changes: 4 additions & 4 deletions examples/i18n/src/templates/about.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use perseus::{is_server, t, Template};
use sycamore::prelude::{component, template, GenericNode, Template as SycamoreTemplate};
use sycamore::prelude::{component, view, Html, View};

#[perseus::template(AboutPage)]
#[component(AboutPage<G>)]
pub fn about_page() -> SycamoreTemplate<G> {
template! {
pub fn about_page() -> View<G> {
view! {
p { (t!("about")) }
p {
(
Expand All @@ -18,6 +18,6 @@ pub fn about_page() -> SycamoreTemplate<G> {
}
}

pub fn get_template<G: GenericNode>() -> Template<G> {
pub fn get_template<G: Html>() -> Template<G> {
Template::new("about").template(about_page)
}
8 changes: 4 additions & 4 deletions examples/i18n/src/templates/index.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use perseus::{link, t, Template};
use sycamore::prelude::{component, template, GenericNode, Template as SycamoreTemplate};
use sycamore::prelude::{component, view, Html, View};

#[perseus::template(IndexPage)]
#[component(IndexPage<G>)]
pub fn index_page() -> SycamoreTemplate<G> {
pub fn index_page() -> View<G> {
let username = "User";
template! {
view! {
p { (t!("hello", {
"user": username
})) }
a(href = link!("/about")) { "About" }
}
}

pub fn get_template<G: GenericNode>() -> Template<G> {
pub fn get_template<G: Html>() -> Template<G> {
Template::new("index").template(index_page)
}
8 changes: 4 additions & 4 deletions examples/i18n/src/templates/post.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use perseus::{link, RenderFnResult, RenderFnResultWithCause, Template};
use serde::{Deserialize, Serialize};
use sycamore::prelude::{component, template, GenericNode, Template as SycamoreTemplate};
use sycamore::prelude::{component, view, Html, View};

#[derive(Serialize, Deserialize)]
pub struct PostPageProps {
Expand All @@ -10,10 +10,10 @@ pub struct PostPageProps {

#[perseus::template(PostPage)]
#[component(PostPage<G>)]
pub fn post_page(props: PostPageProps) -> SycamoreTemplate<G> {
pub fn post_page(props: PostPageProps) -> View<G> {
let title = props.title;
let content = props.content;
template! {
view! {
h1 {
(title)
}
Expand All @@ -26,7 +26,7 @@ pub fn post_page(props: PostPageProps) -> SycamoreTemplate<G> {
}
}

pub fn get_template<G: GenericNode>() -> Template<G> {
pub fn get_template<G: Html>() -> Template<G> {
Template::new("post")
.build_paths_fn(get_static_paths)
.build_state_fn(get_static_props)
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"

[dependencies]
perseus = { path = "../../packages/perseus" }
sycamore = "0.6"
sycamore = "0.7"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
toml = "0.5"
Expand Down
10 changes: 5 additions & 5 deletions examples/plugins/src/error_pages.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use perseus::{ErrorPages, GenericNode};
use sycamore::template;
use perseus::{ErrorPages, Html};
use sycamore::view;

pub fn get_error_pages<G: GenericNode>() -> ErrorPages<G> {
pub fn get_error_pages<G: Html>() -> ErrorPages<G> {
let mut error_pages = ErrorPages::new(|url, status, err, _| {
template! {
view! {
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
}
});
error_pages.add_page(404, |_, _, _, _| {
template! {
view! {
p { "Page not found." }
}
});
Expand Down
Loading

0 comments on commit 3989241

Please sign in to comment.