fix web playwright tests

This commit is contained in:
Evan Almloff 2024-02-05 15:24:38 -06:00
parent 1bbceac4e1
commit c431429448
10 changed files with 21 additions and 11 deletions

2
Cargo.lock generated
View file

@ -2811,6 +2811,8 @@ version = "0.0.1"
dependencies = [
"dioxus",
"serde_json",
"tracing",
"tracing-wasm",
]
[[package]]

View file

@ -66,8 +66,8 @@ dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" }
dioxus-html = { path = "packages/html", version = "0.4.0" }
dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.4.0" }
dioxus-hooks = { path = "packages/hooks", version = "0.4.0" }
dioxus-web = { path = "packages/web", version = "0.4.0", default-features = false }
dioxus-ssr = { path = "packages/ssr", version = "0.4.0", default-features = false }
dioxus-web = { path = "packages/web", version = "0.4.0" }
dioxus-ssr = { path = "packages/ssr", version = "0.4.0", default-features = false }
dioxus-desktop = { path = "packages/desktop", version = "0.4.0" }
dioxus-mobile = { path = "packages/mobile", version = "0.4.0" }
dioxus-interpreter-js = { path = "packages/interpreter", version = "0.4.0" }

View file

@ -45,8 +45,9 @@ pub fn provide_context<T: 'static + Clone>(value: T) -> T {
}
/// Provide a context to the root scope
pub fn provide_root_context<T: 'static + Clone>(value: T) -> Option<T> {
pub fn provide_root_context<T: 'static + Clone>(value: T) -> T {
Runtime::with_current_scope(|cx| cx.provide_root_context(value))
.expect("to be in a dioxus runtime")
}
/// Suspends the current component

View file

@ -5,6 +5,6 @@ pub fn use_root_context<T: 'static + Clone>(new: impl FnOnce() -> T) -> T {
use_hook(|| {
try_consume_context::<T>()
// If no context is provided, create a new one at the root
.unwrap_or_else(|| provide_root_context(new()).expect(" A runtime to exist"))
.unwrap_or_else(|| provide_root_context(new()))
})
}

File diff suppressed because one or more lines are too long

View file

@ -82,7 +82,7 @@ module.exports = defineConfig({
},
{
cwd: path.join(process.cwd(), "web"),
command: "cargo run --package dioxus-cli --release -- serve --skip-assets",
command: "cargo run --package dioxus-cli --release -- serve",
port: 8080,
timeout: 20 * 60 * 1000,
reuseExistingServer: !process.env.CI,
@ -90,7 +90,7 @@ module.exports = defineConfig({
},
{
cwd: path.join(process.cwd(), 'fullstack'),
command: 'cargo run --package dioxus-cli --release -- serve --platform fullstack --skip-assets',
command: 'cargo run --package dioxus-cli --release -- serve --platform fullstack',
port: 3333,
timeout: 20 * 60 * 1000,
reuseExistingServer: !process.env.CI,

View file

@ -9,3 +9,5 @@ publish = false
[dependencies]
dioxus = { workspace = true, features = ["web"]}
serde_json = "1.0.96"
tracing.workspace = true
tracing-wasm = "0.2.1"

View file

@ -43,5 +43,10 @@ fn app() -> Element {
}
fn main() {
tracing_wasm::set_as_global_default_with_config(
tracing_wasm::WASMLayerConfigBuilder::default()
.set_max_level(tracing::Level::TRACE)
.build(),
);
launch(app);
}

View file

@ -19,7 +19,7 @@ pub(crate) fn get_global_context() -> GlobalSignalContext {
let context = GlobalSignalContext {
signal: Rc::new(RefCell::new(HashMap::new())),
};
provide_root_context(context).unwrap()
provide_root_context(context)
}
}
}

View file

@ -1,4 +1,4 @@
use dioxus_core::ScopeId;
use core::panic;
use dioxus_html::prelude::{EvalError, EvalProvider, Evaluator};
use futures_util::StreamExt;
use generational_box::{AnyStorage, GenerationalBox, UnsyncStorage};
@ -9,8 +9,8 @@ use wasm_bindgen::prelude::*;
/// Provides the WebEvalProvider through [`cx.provide_context`].
pub fn init_eval() {
let provider: Rc<dyn EvalProvider> = Rc::new(WebEvalProvider {});
ScopeId::ROOT.provide_context(provider);
let provider: Rc<dyn EvalProvider> = Rc::new(WebEvalProvider);
dioxus_core::ScopeId::ROOT.provide_context(provider);
}
/// Represents the web-target's provider of evaluators.