Skip to content

Commit 2017f69

Browse files
authored
feat: remove localized global state (#268)
* feat: removed localized global state This completely axes the feature, and returns global state to a one-per-app system. BREAKING CHANGE: removed localized global state (global state functions should no longer take a locale) * fix: transmitted global state in locale redirection pages This fixes #267, but only when global state is unlocalized. * fix: fixed broken examples * fix: fixed broken demo example * chore(deps): updated dependencies extensively Not strictly relevant to this PR, but important nonetheless. Note that this includes a progression of the `minify-html-onepass` crate version, which *could* cause problems, so that should be reverted to v0.10.1 if there are issues.
1 parent 9aa079b commit 2017f69

File tree

40 files changed

+118
-153
lines changed

40 files changed

+118
-153
lines changed

examples/core/basic/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/capsules/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ serde_json = "1"
1313
lazy_static = "1"
1414

1515
[target.'cfg(engine)'.dev-dependencies]
16-
fantoccini = "0.17"
16+
fantoccini = "0.19"
1717

1818
[target.'cfg(engine)'.dependencies]
1919
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/custom_server/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/error_views/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/freezing_and_thawing/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/freezing_and_thawing/src/global_state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct AppState {
1212
}
1313

1414
#[engine_only_fn]
15-
async fn get_build_state(_locale: String) -> AppState {
15+
async fn get_build_state() -> AppState {
1616
AppState {
1717
test: "Hello World!".to_string(),
1818
}

examples/core/global_state/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/global_state/src/global_state.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct AppState {
2222
// Global state will be generated for each locale in your app (but we don't
2323
// worry about that in this example)
2424
#[engine_only_fn]
25-
async fn get_build_state(_locale: String) -> AppState {
25+
async fn get_build_state() -> AppState {
2626
AppState {
2727
test: "Hello from the build process!".to_string(),
2828
}
@@ -34,19 +34,15 @@ async fn get_build_state(_locale: String) -> AppState {
3434
// prevent your app from accessing global state during the build process, so be
3535
// certain that's what you want if you go down that path.
3636
#[engine_only_fn]
37-
async fn get_request_state(_locale: String, _req: Request) -> AppState {
37+
async fn get_request_state(_req: Request) -> AppState {
3838
AppState {
3939
test: "Hello from the server!".to_string(),
4040
}
4141
}
4242

4343
// You can even combine build state with request state, just like in a template!
4444
#[engine_only_fn]
45-
async fn amalgamate_states(
46-
_locale: String,
47-
build_state: AppState,
48-
request_state: AppState,
49-
) -> AppState {
45+
async fn amalgamate_states(build_state: AppState, request_state: AppState) -> AppState {
5046
AppState {
5147
test: format!(
5248
"Message from the builder: '{}' Message from the server: '{}'",

examples/core/helper_build_state/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/i18n/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fluent-bundle = "0.15"
1515
urlencoding = "2.1"
1616

1717
[dev-dependencies]
18-
fantoccini = "0.17"
18+
fantoccini = "0.19"
1919

2020
[target.'cfg(engine)'.dependencies]
2121
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/idb_freezing/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ serde_json = "1"
1313
wasm-bindgen-futures = "0.4"
1414

1515
[dev-dependencies]
16-
fantoccini = "0.17"
16+
fantoccini = "0.19"
1717

1818
[target.'cfg(engine)'.dependencies]
1919
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/idb_freezing/src/global_state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct AppState {
1212
}
1313

1414
#[engine_only_fn]
15-
async fn get_build_state(_locale: String) -> AppState {
15+
async fn get_build_state() -> AppState {
1616
AppState {
1717
test: "Hello World!".to_string(),
1818
}

examples/core/index_view/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/js_interop/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/plugins/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ perseus = { path = "../../../packages/perseus", features = [ "hydrate" ] }
1010
sycamore = "^0.8.1"
1111
serde = { version = "1", features = [ "derive" ] }
1212
serde_json = "1"
13-
toml = "0.5"
13+
toml = "0.7"
1414

1515
[dev-dependencies]
16-
fantoccini = "0.17"
16+
fantoccini = "0.19"
1717

1818
[target.'cfg(engine)'.dependencies]
1919
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/preload/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/rx_state/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/set_headers/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616
ureq = "2"
1717

1818
[target.'cfg(engine)'.dependencies]

examples/core/state_generation/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ serde_json = "1"
1313
anyhow = "1"
1414

1515
[dev-dependencies]
16-
fantoccini = "0.17"
16+
fantoccini = "0.19"
1717

1818
[target.'cfg(engine)'.dependencies]
1919
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/state_generation/src/templates/incremental_generation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ async fn get_build_state(
5656
// This tells Perseus to return an error that's the client's fault, with the
5757
// HTTP status code 404 (not found) and the message 'illegal page'. Note that
5858
// this is a `BlamedError<std::io::Error>`, but we could use any error type that
59-
// implements `std::error::Error` or can be converted into a boxed `std::error::Error`.
59+
// implements `std::error::Error` or can be converted into a boxed
60+
// `std::error::Error`.
6061
return Err(BlamedError {
6162
// If we used `None` instead, it would default to 400 for the client and 500 for the
6263
// server

examples/core/static_content/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/suspense/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/core/unreactive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

examples/demos/auth/src/global_state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn get_global_state_creator() -> GlobalStateCreator {
66
}
77

88
#[engine_only_fn]
9-
async fn get_build_state(_locale: String) -> AppState {
9+
async fn get_build_state() -> AppState {
1010
AppState {
1111
// We explicitly tell the first page that no login state has been checked yet
1212
auth: AuthData {

examples/demos/fetching/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ perseus-axum = { package = "perseus-integration", path = "../../../packages/pers
2020
reqwest = "0.11"
2121

2222
[target.'cfg(client)'.dependencies]
23-
reqwasm = "0.4"
23+
reqwasm = "0.5"

examples/demos/full_page_layout/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
1212
serde_json = "1"
1313

1414
[target.'cfg(engine)'.dev-dependencies]
15-
fantoccini = "0.17"
15+
fantoccini = "0.19"
1616

1717
[target.'cfg(engine)'.dependencies]
1818
tokio = { version = "1", features = [ "macros", "rt", "rt-multi-thread" ] }

packages/perseus-actix-web/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ categories = ["wasm", "web-programming::http-server", "development-tools", "asyn
1515

1616
[dependencies]
1717
perseus = { path = "../perseus", version = "0.4.0-beta.22" }
18-
actix-web = "4.2"
18+
actix-web = "4.3"
1919
actix-files = "0.6"
2020
futures = "0.3"
2121

packages/perseus-axum/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ categories = ["wasm", "web-programming::http-server", "development-tools", "asyn
1616
[dependencies]
1717
perseus = { path = "../perseus", version = "0.4.0-beta.22" }
1818
axum = "0.6"
19+
# Axum requires v0.3 of this
1920
tower-http = { version = "0.3", features = [ "fs" ] }
2021

2122
[features]

packages/perseus-cli/Cargo.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@ path = "tests/lib.rs"
2727
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2828

2929
[dependencies]
30-
include_dir = "0.6"
30+
include_dir = "0.7"
3131
thiserror = "1"
3232
fmterr = "0.1"
3333
cargo_toml = "0.15"
3434
indicatif = "=0.17.0-beta.1" # Not stable, but otherwise error handling is just about impossible
35-
console = "0.14"
35+
console = "0.15"
3636
serde = "1"
3737
serde_json = "1"
38-
clap = { version = "3.2", features = [ "color", "derive", "unstable-v4" ] }
38+
clap = { version = "4.2", features = [ "color", "derive" ] }
3939
fs_extra = "1"
4040
tokio = { version = "1", features = [ "macros", "rt-multi-thread", "sync" ] }
4141
warp = "0.3"
42-
command-group = "1"
43-
ctrlc = { version = "3.0", features = ["termination"] }
42+
command-group = "2"
43+
ctrlc = { version = "3.2", features = ["termination"] }
4444
notify = "=5.0.0-pre.13"
4545
futures = "0.3"
4646
tokio-stream = "0.1"
4747
reqwest = { version = "0.11", features = [ "json", "stream" ] }
4848
tar = "0.4"
4949
flate2 = "1"
50-
directories = "4"
50+
directories = "5"
5151
cargo_metadata = "0.15"
5252
cargo-lock = "8"
53-
minify-js = "0.4"
53+
minify-js = "=0.4.3" # Be careful changing this, and test extensively!
5454
walkdir = "2"
5555

5656
[dev-dependencies]
5757
assert_cmd = "2"
5858
assert_fs = "1"
59-
predicates = "2"
59+
predicates = "3"
6060
ureq = "2"
6161

6262
[lib]

packages/perseus-macro/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ proc-macro = true
1717

1818
[dependencies]
1919
quote = "1"
20-
syn = "1"
20+
syn = "1" # Needs to remain on v1 until `darling` updates
2121
proc-macro2 = "1"
22-
darling = "0.13"
22+
darling = "0.14"
2323

2424
[dev-dependencies]
2525
trybuild = { version = "1.0", features = ["diff"] }

packages/perseus/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ http = "0.2"
3636
urlencoding = "2.1"
3737
chrono = "0.4"
3838
# Be very careful about changing this! Patches may be required in Perseus.
39-
minify-html-onepass = "=0.10.1"
39+
minify-html-onepass = "=0.10.8"
4040

4141
# These dependencies will also be available in documentation
4242
[target.'cfg(any(client, clientdoc))'.dependencies]
4343
rexie = { version = "0.4", optional = true, default-features = false }
4444
js-sys = { version = "0.3", optional = true }
4545
# Note that this is not needed in production, but that can't be specified, so it will just be compiled away to nothing
46-
console_error_panic_hook = { version = "0.1.6", optional = true }
46+
console_error_panic_hook = { version = "0.1.7", optional = true }
4747
# TODO review feature flags here
4848
web-sys = { version = "0.3", features = [ "Headers", "Navigator", "NodeList", "Request", "RequestInit", "RequestMode", "Response", "ReadableStream", "Window", "CustomEvent", "CustomEventInit" ] }
4949
wasm-bindgen = "0.2"

packages/perseus/src/reactor/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ impl<G: Html, M: MutableStore, T: TranslationsManager> TryFrom<PerseusAppBase<G,
162162
return Err(ClientInvariantError::RenderCfg.into())
163163
}
164164
};
165+
// NOTE: This will be transmitted on all pages, including local redirection ones
165166
let global_state_ty = match WindowVariable::<Value>::new_obj("__PERSEUS_GLOBAL_STATE") {
166167
WindowVariable::Some(val) => {
167168
let state = TemplateState::from_value(val);

packages/perseus/src/server/html_shell.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,18 @@ impl HtmlShell {
267267
///
268268
/// Further, this will preload the Wasm binary, making redirection snappier
269269
/// (but initial load slower), a tradeoff that generally improves UX.
270-
pub(crate) fn locale_redirection_fallback(mut self, redirect_url: &str) -> Self {
270+
pub(crate) fn locale_redirection_fallback(
271+
mut self,
272+
redirect_url: &str,
273+
global_state: &TemplateState,
274+
) -> Self {
271275
self.locale = "xx-XX".to_string();
276+
277+
// We still have to inject the global state, which is unlocalized (see #267)
278+
let global_state = escape_page_data(&global_state.state.to_string());
279+
let global_state = format!("window.__PERSEUS_GLOBAL_STATE = `{}`;", global_state);
280+
self.scripts_before_boundary.push(global_state);
281+
272282
// This will be used if JavaScript is completely disabled (it's then the site's
273283
// responsibility to show a further message)
274284
let dumb_redirect = format!(

0 commit comments

Comments
 (0)