From b09b2f9b5f15873b0b24fffde08c8203d0f79aba Mon Sep 17 00:00:00 2001 From: Matt Hunzinger Date: Thu, 20 Jun 2024 18:21:28 -0400 Subject: [PATCH] Fix panic on root node and clean up --- packages/dioxus-blitz/src/lib.rs | 14 ++++++++------ packages/dioxus-blitz/src/window.rs | 7 +------ packages/dom/src/document.rs | 4 +++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/dioxus-blitz/src/lib.rs b/packages/dioxus-blitz/src/lib.rs index dd9f9ae9..1b320639 100644 --- a/packages/dioxus-blitz/src/lib.rs +++ b/packages/dioxus-blitz/src/lib.rs @@ -12,7 +12,7 @@ use documents::DioxusDocument; use muda::{MenuEvent, MenuId}; use std::collections::HashMap; use url::Url; -use winit::event_loop::{EventLoop, EventLoopBuilder}; +use winit::event_loop::EventLoop; use winit::window::WindowId; use winit::{ event::{Event, WindowEvent}, @@ -126,6 +126,9 @@ fn launch_with_window(window: View<'static, Doc>) { }); } + // the move to winit wants us to use a struct with a run method instead of the callback approach + // we want to just keep the callback approach for now + #[allow(deprecated)] event_loop .run(move |event, event_loop| { event_loop.set_control_flow(ControlFlow::Wait); @@ -190,8 +193,6 @@ fn launch_with_window(window: View<'static, Doc>) { ))] Event::UserEvent(UserEvent::HotReloadEvent(msg)) => match msg { dioxus_hot_reload::HotReloadMsg::UpdateTemplate(template) => { - dbg!("Update template {:?}", template); - for window in windows.values_mut() { if let Some(dx_doc) = window .renderer @@ -200,15 +201,16 @@ fn launch_with_window(window: View<'static, Doc>) { .downcast_mut::() { dx_doc.vdom.replace_template(template); - } - if window.poll() { - window.request_redraw(); + if window.poll() { + window.request_redraw(); + } } } } dioxus_hot_reload::HotReloadMsg::Shutdown => event_loop.exit(), dioxus_hot_reload::HotReloadMsg::UpdateAsset(asset) => { + // TODO dioxus-desktop seems to handle this by forcing a reload of all stylesheets. dbg!("Update asset {:?}", asset); } }, diff --git a/packages/dioxus-blitz/src/window.rs b/packages/dioxus-blitz/src/window.rs index b0599100..4a7ebc7a 100644 --- a/packages/dioxus-blitz/src/window.rs +++ b/packages/dioxus-blitz/src/window.rs @@ -1,9 +1,7 @@ use crate::waker::UserEvent; use blitz::{RenderState, Renderer, Viewport}; use blitz_dom::DocumentLike; -use wgpu::rwh::HasWindowHandle; use winit::keyboard::PhysicalKey; -use winit::window::WindowAttributes; use std::sync::Arc; use std::task::Waker; @@ -19,8 +17,6 @@ use winit::event_loop::{ActiveEventLoop, EventLoopProxy}; target_os = "openbsd" ))] use winit::platform::unix::WindowExtUnix; -#[cfg(target_os = "windows")] -use winit::platform::windows::WindowExtWindows; use winit::{event::WindowEvent, keyboard::KeyCode, keyboard::ModifiersState, window::Window}; #[cfg(not(target_os = "macos"))] @@ -224,7 +220,7 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> { }; if let RenderState::Active(state) = &self.renderer.render_state { - state.window.set_cursor_icon(tao_cursor); + state.window.set_cursor(tao_cursor); self.request_redraw(); } } @@ -248,7 +244,6 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> { winit::event::MouseScrollDelta::PixelDelta(offsets) => { self.renderer.scroll_by(offsets.y) } - _ => {} }; self.request_redraw(); } diff --git a/packages/dom/src/document.rs b/packages/dom/src/document.rs index 395c5f91..ab1d5e42 100644 --- a/packages/dom/src/document.rs +++ b/packages/dom/src/document.rs @@ -222,7 +222,9 @@ impl Document { let node = &self.nodes[node_id]; let node_child_idx = node.child_idx; - let parent_id = node.parent.unwrap(); + + // Get this node's parent, or the root node if it has none. + let parent_id = node.parent.unwrap_or_default(); let parent = &mut self.nodes[parent_id]; let mut children = std::mem::take(&mut parent.children);