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
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-07-30 17:16:27 +00:00
1 parent f3ca1484a1
commit 34bdcd15cf
40 files changed
+2288 -1897

No files matched your search

+10 -33
View File
@@ -1,43 +1,20 @@
use crate::HotReloadMsg;
use dioxus_core::{internal::HotReloadLiteral, ScopeId, VirtualDom};
use dioxus_core::{ScopeId, VirtualDom};
use dioxus_signals::Writable;
/// Applies template and literal changes to the VirtualDom
///
/// Assets need to be handled by the renderer.
pub fn apply_changes(dom: &mut VirtualDom, msg: &HotReloadMsg) {
for templates in &msg.templates {
for template in &templates.templates {
dom.replace_template(*template);
}
dom.runtime().on_scope(ScopeId::ROOT, || {
let ctx = dioxus_signals::get_global_context();
dom.runtime().on_scope(ScopeId::ROOT, || {
let ctx = dioxus_signals::get_global_context();
for (id, literal) in templates.changed_lits.iter() {
match &literal {
HotReloadLiteral::Fmted(f) => {
if let Some(mut signal) = ctx.get_signal_with_key(id) {
signal.set(f.clone());
}
}
HotReloadLiteral::Float(f) => {
if let Some(mut signal) = ctx.get_signal_with_key::<f64>(id) {
signal.set(*f);
}
}
HotReloadLiteral::Int(f) => {
if let Some(mut signal) = ctx.get_signal_with_key::<i64>(id) {
signal.set(*f);
}
}
HotReloadLiteral::Bool(f) => {
if let Some(mut signal) = ctx.get_signal_with_key::<bool>(id) {
signal.set(*f);
}
}
}
for template in &msg.templates {
let id = &template.location;
let value = template.template.clone();
if let Some(mut signal) = ctx.get_signal_with_key(id) {
signal.set(value);
}
});
}
}
});
}
+2 -2
View File
@@ -1,4 +1,4 @@
use dioxus_rsx::HotReloadedTemplate;
use dioxus_core::internal::HotReloadTemplateWithLocation;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
@@ -49,7 +49,7 @@ pub enum ClientMsg {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(bound(deserialize = "'de: 'static"))]
pub struct HotReloadMsg {
pub templates: Vec<HotReloadedTemplate>,
pub templates: Vec<HotReloadTemplateWithLocation>,
pub assets: Vec<PathBuf>,
/// A file changed that's not an asset or a rust file - best of luck!