Files
dioxus/packages/hot-reload/src/lib.rs
T
Evan Almloff 34bdcd15cf Switch to a pool of dynamic values for hot reloading (#2705)
* create the dynamic value pool

* assign ids to dynamic formatted segments

* separate the rendering and literal pools

* rsx output compiles again

* more examples compiling with new rsx expansion

* update template body explanation

* all workspace examples compile

* fix formatted segments in keys

* start hot reload diffing

* fix component literal hot reloading

* start integrate new hot reloading with the CLI

* simple hot reloads working

* Fix hot reloading blocks with components

* implement hot reloading for if chains

* Fix hot reloading after a template requires a full rebuild

* Fix hot reloading any attribute values

* remove unsafe from hot reload utils

* Fix hot reloading empty rsx

* add more hot reloading tests

* reorganize hot reload module

* fix web hydration

* fix empty rsx nodes in autoformatting

* fix tests

* remove path sorting logic from core

* make template names more consistent in debug mode

* fix quote_as_hot_reload_literal for explicitly typed literals

* fix can_be_shorthand for string literals

* fix formatted single dynamic expression

* Fix usize component properties and playwright tests

* remove default implementation for TemplateBody

* add a bunch more comments for diffing, scoring and why this scoring system is optimal
2024-07-30 17:16:27 +00:00

72 lines
1.8 KiB
Rust

use dioxus_core::internal::HotReloadTemplateWithLocation;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[cfg(feature = "client")]
mod client;
#[cfg(feature = "client")]
pub use client::*;
#[cfg(feature = "serve")]
mod ws_receiver;
#[cfg(feature = "serve")]
pub use ws_receiver::*;
/// A message the hot reloading server sends to the client
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(bound(deserialize = "'de: 'static"))]
pub enum DevserverMsg {
/// Attempt a hotreload
/// This includes all the templates/literals/assets/binary patches that have changed in one shot
HotReload(HotReloadMsg),
/// The devserver is starting a full rebuild.
FullReloadStart,
/// The full reload failed.
FullReloadFailed,
/// The app should reload completely if it can
FullReloadCommand,
/// The program is shutting down completely - maybe toss up a splash screen or something?
Shutdown,
}
/// A message the client sends from the frontend to the devserver
///
/// This is used to communicate with the devserver
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub enum ClientMsg {
Log {
level: String,
messages: Vec<String>,
},
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(bound(deserialize = "'de: 'static"))]
pub struct HotReloadMsg {
pub templates: Vec<HotReloadTemplateWithLocation>,
pub assets: Vec<PathBuf>,
/// A file changed that's not an asset or a rust file - best of luck!
pub unknown_files: Vec<PathBuf>,
}
#[test]
fn serialize_client_msg() {
let msg = ClientMsg::Log {
level: "info".to_string(),
messages: vec!["hello world".to_string()],
};
let json = serde_json::to_string(&msg).unwrap();
assert_eq!(
json,
r#"{"Log":{"level":"info","messages":["hello world"]}}"#
);
}