Skip to content

Commit

Permalink
Fix panic on root node and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jun 20, 2024
1 parent 21e11b6 commit b09b2f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
14 changes: 8 additions & 6 deletions packages/dioxus-blitz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -126,6 +126,9 @@ fn launch_with_window<Doc: DocumentLike + 'static>(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);
Expand Down Expand Up @@ -190,8 +193,6 @@ fn launch_with_window<Doc: DocumentLike + 'static>(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
Expand All @@ -200,15 +201,16 @@ fn launch_with_window<Doc: DocumentLike + 'static>(window: View<'static, Doc>) {
.downcast_mut::<DioxusDocument>()
{
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);
}
},
Expand Down
7 changes: 1 addition & 6 deletions packages/dioxus-blitz/src/window.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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"))]
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion packages/dom/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b09b2f9

Please sign in to comment.