mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
improve the error that triggers on when you try to use eval on the server in fullstack (#2502)
This commit is contained in:
parent
c0246c26e0
commit
acb1b0755a
1 changed files with 5 additions and 1 deletions
|
@ -58,6 +58,7 @@ pub fn eval(script: &str) -> UseEval {
|
||||||
struct DummyProvider;
|
struct DummyProvider;
|
||||||
impl EvalProvider for DummyProvider {
|
impl EvalProvider for DummyProvider {
|
||||||
fn new_evaluator(&self, _js: String) -> GenerationalBox<Box<dyn Evaluator>> {
|
fn new_evaluator(&self, _js: String) -> GenerationalBox<Box<dyn Evaluator>> {
|
||||||
|
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))
|
UnsyncStorage::owner().insert(Box::new(DummyEvaluator))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,10 @@ impl UseEval {
|
||||||
|
|
||||||
/// Sends a [`serde_json::Value`] to the evaluated JavaScript.
|
/// Sends a [`serde_json::Value`] to the evaluated JavaScript.
|
||||||
pub fn send(&self, data: serde_json::Value) -> Result<(), EvalError> {
|
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.
|
/// Gets an UnboundedReceiver to receive messages from the evaluated JavaScript.
|
||||||
|
|
Loading…
Reference in a new issue