From acb1b0755ada90e2908b20b2e12976365a19bd30 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 11 Jun 2024 03:48:16 +0200 Subject: [PATCH] improve the error that triggers on when you try to use eval on the server in fullstack (#2502) --- packages/html/src/eval.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/html/src/eval.rs b/packages/html/src/eval.rs index 84ef89e7f..f8179b09e 100644 --- a/packages/html/src/eval.rs +++ b/packages/html/src/eval.rs @@ -58,6 +58,7 @@ pub fn eval(script: &str) -> UseEval { struct DummyProvider; impl EvalProvider for DummyProvider { fn new_evaluator(&self, _js: String) -> GenerationalBox> { + tracing::error!("Eval is not supported on this platform. If you are using dioxus fullstack, you can wrap your code with `client! {{}}` to only include the code that runs eval in the client bundle."); UnsyncStorage::owner().insert(Box::new(DummyEvaluator)) } } @@ -103,7 +104,10 @@ impl UseEval { /// Sends a [`serde_json::Value`] to the evaluated JavaScript. pub fn send(&self, data: serde_json::Value) -> Result<(), EvalError> { - self.evaluator.read().send(data) + match self.evaluator.try_read() { + Ok(evaluator) => evaluator.send(data), + Err(_) => Err(EvalError::Finished), + } } /// Gets an UnboundedReceiver to receive messages from the evaluated JavaScript.