Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 126 additions & 164 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ smallvec = "1"
thin-vec = "0.2"

# DioxusLabs dependencies
dioxus = { version = "0.7.3" }
dioxus-core = { version = "0.7.3" }
dioxus-html = { version = "0.7.3" }
dioxus-hooks = { version = "0.7.3" }
dioxus-signals = { version = "0.7.3" }
dioxus-stores = { version = "0.7.3" }
dioxus-asset-resolver = { version = "0.7.3" }
manganis = { version = "0.7.3" }
dioxus-document = { version = "0.7.3" }
dioxus-history = { version = "0.7.3" }
dioxus = { version = "0.8.0-alpha.3" }
dioxus-core = { version = "0.8.0-alpha.3" }
dioxus-html = { version = "0.8.0-alpha.3" }
dioxus-hooks = { version = "0.8.0-alpha.3" }
dioxus-signals = { version = "0.8.0-alpha.3" }
dioxus-stores = { version = "0.8.0-alpha.3" }
dioxus-asset-resolver = { version = "0.8.0-alpha.3" }
manganis = { version = "0.8.0-alpha.3" }
dioxus-document = { version = "0.8.0-alpha.3" }
dioxus-history = { version = "0.8.0-alpha.3" }

# Dioxus hot reload
dioxus-devtools = { version = "0.7.3" }
dioxus-cli-config = { version = "0.7.3" }
dioxus-devtools = { version = "0.8.0-alpha.3" }
dioxus-cli-config = { version = "0.8.0-alpha.3" }

# Dioxus Prelude
dioxus-core-macro = { version = "0.7.3" }
dioxus-core-macro = { version = "0.8.0-alpha.3" }

# Taffy + Parley + Fontations
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "802e497b69689e1c93be2d16e9d53a973971bcb2", default-features = false, features = [
Expand Down
6 changes: 3 additions & 3 deletions apps/browser/src/browser_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ impl BrowsingHistory {

#[store(pub)]
impl<Lens> Store<BrowsingHistory, Lens> {
fn record_visit(&self, entry: HistoryEntry) -> HistoryEntryId
pub(crate) fn record_visit(&self, entry: HistoryEntry) -> HistoryEntryId
where
Lens: Writable,
{
record_visit_inner(&mut self.entries().write(), entry)
}

fn set_favicon_by_id(&self, id: HistoryEntryId, favicon_url: Url)
pub(crate) fn set_favicon_by_id(&self, id: HistoryEntryId, favicon_url: Url)
where
Lens: Writable,
{
set_favicon_by_id_inner(&mut self.entries().write(), id, favicon_url);
}

fn clear(&self)
pub(crate) fn clear(&self)
where
Lens: Writable,
{
Expand Down
18 changes: 7 additions & 11 deletions apps/browser/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,31 @@ impl History {

#[store]
impl<Lens> Store<History, Lens> {
fn current_idx(&self) -> usize {
pub(crate) fn current_idx(&self) -> usize {
*self.current().read()
}

fn current_url(&self) -> impl Readable<Target = Request> {
self.urls().get(self.current_idx()).unwrap()
}

fn has_back(&self) -> bool {
pub(crate) fn has_back(&self) -> bool {
self.current_idx() > 0
}

fn has_forward(&self) -> bool {
pub(crate) fn has_forward(&self) -> bool {
self.current_idx() < self.urls().len() - 1
}

fn go_back(&mut self) {
pub(crate) fn go_back(&mut self) {
if self.has_back() {
*self.current().write() -= 1;
}
}

fn go_forward(&mut self) {
pub(crate) fn go_forward(&mut self) {
if self.has_forward() {
*self.current().write() += 1;
}
}

fn navigate(&self, req: Request)
pub(crate) fn navigate(&self, req: Request)
where
Lens: Writable,
{
Expand All @@ -74,7 +70,7 @@ pub trait HistoryNav {

impl HistoryNav for SyncStore<History> {
fn current_url(&self) -> impl Readable<Target = Request> {
HistoryStoreImplExt::current_url(self)
self.urls().get(self.current_idx()).unwrap()
}

fn has_back(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions apps/browser/src/nav.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use blitz_traits::navigation::NavigationOptions;
use blitz_traits::net::{Method, Request, Url};
use dioxus_native::prelude::Key;
use dioxus_native::prelude::{Key, NamedKey};

pub fn req_from_string(url_s: &str) -> Option<Request> {
if let Ok(url) = Url::parse(url_s) {
Expand Down Expand Up @@ -40,5 +40,5 @@ pub fn open_in_external_browser(req: &Request) {
}

pub fn is_enter_key(key: &Key) -> bool {
matches!(key, Key::Enter) || matches!(key, Key::Character(s) if s == "\n")
matches!(key, Key::Named(NamedKey::Enter)) || matches!(key, Key::Character(s) if s == "\n")
}
16 changes: 8 additions & 8 deletions apps/browser/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,42 @@ pub struct Tab {

#[store(pub)]
impl<Lens> Store<Tab, Lens> {
fn nav_history(&self) -> SyncStore<History> {
pub(crate) fn nav_history(&self) -> SyncStore<History> {
*self.history().read()
}

fn loader_rc(&self) -> Rc<DocumentLoader> {
pub(crate) fn loader_rc(&self) -> Rc<DocumentLoader> {
// `open_tab` always assigns Some(loader) immediately after pushing the
// tab, so by the time any view code can call this the loader is set.
#[allow(clippy::expect_used)]
self.loader().cloned().expect("loader uninitialized")
}

fn tab_id(&self) -> TabId {
pub(crate) fn tab_id(&self) -> TabId {
*self.id().read()
}

fn navigate(&self, req: Request) {
pub(crate) fn navigate(&self, req: Request) {
self.nav_history().navigate(req);
}

fn reload(&self) {
pub(crate) fn reload(&self) {
self.loader_rc().reload();
}

fn go_back(&self) {
pub(crate) fn go_back(&self) {
self.nav_history().go_back();
}

fn go_forward(&self) {
pub(crate) fn go_forward(&self) {
self.nav_history().go_forward();
}

// Chrome state (title, favicon) for about pages. About URLs never go
// through the document loader, so this is the only place their title is
// set and the only place a stale favicon from a previous real page gets
// cleared.
fn commit_about_chrome(&self, page: AboutPage)
pub(crate) fn commit_about_chrome(&self, page: AboutPage)
where
Lens: Writable,
{
Expand Down
6 changes: 3 additions & 3 deletions apps/browser/src/toolbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ pub fn Toolbar(
onkeydown: move |evt| {
let key = evt.key();
match &key {
Key::ArrowDown => {
Key::Named(NamedKey::ArrowDown) => {
evt.prevent_default();
move_selection_down(());
}
Key::ArrowUp => {
Key::Named(NamedKey::ArrowUp) => {
evt.prevent_default();
move_selection_up(());
}
Key::Escape => {
Key::Named(NamedKey::Escape) => {
evt.prevent_default();
blur_urlbar(());
}
Expand Down
2 changes: 1 addition & 1 deletion examples/seven_guis/src/tasks/cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ pub fn Cells() -> Element {
selected.set(None);
},
onkeydown: move |evt| {
if evt.key() == Key::Enter {
if evt.key() == Key::Named(NamedKey::Enter) {
sheet.write().raw.insert((r, c), edit_val());
selected.set(None);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/todomvc/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn TodoHeader(mut todos: Signal<HashMap<u32, TodoItem>>) -> Element {

let onkeydown = move |evt: KeyboardEvent| {
let is_enter = match evt.key() {
Key::Enter => true,
Key::Named(NamedKey::Enter) => true,
Key::Character(s) if s == "\n" => true,
_ => false,
};
Expand Down Expand Up @@ -205,7 +205,7 @@ fn TodoEntry(mut todos: Signal<HashMap<u32, TodoItem>>, id: u32) -> Element {
autofocus: "true",
onfocusout: move |_| is_editing.set(false),
onkeydown: move |evt| {
if matches!(evt.key(), Key::Enter | Key::Escape | Key::Tab) {
if matches!(evt.key(), Key::Named(NamedKey::Enter) | Key::Named(NamedKey::Escape) | Key::Named(NamedKey::Tab)) {
evt.prevent_default();
is_editing.set(false);
}
Expand Down
12 changes: 4 additions & 8 deletions examples/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn app() -> Element {
let coords = evt.client_coordinates();
if evt
.held_buttons()
.contains(dioxus_elements::input_data::MouseButton::Auxiliary)
.contains(dioxus_html::input_data::MouseButton::Auxiliary)
{
active_pointer.set(true);
last.set([coords.x as f32, coords.y as f32]);
Expand Down Expand Up @@ -88,13 +88,9 @@ fn app() -> Element {
let sensitivity = 0.001;

let delta = match e.delta() {
dioxus_elements::geometry::WheelDelta::Pixels(data) => data.y as f32 * sensitivity,
dioxus_elements::geometry::WheelDelta::Lines(data) => {
data.y as f32 * sensitivity * 16.0
}
dioxus_elements::geometry::WheelDelta::Pages(data) => {
data.y as f32 * sensitivity * 400.0
}
dioxus_html::geometry::WheelDelta::Pixels(data) => data.y as f32 * sensitivity,
dioxus_html::geometry::WheelDelta::Lines(data) => data.y as f32 * sensitivity * 16.0,
dioxus_html::geometry::WheelDelta::Pages(data) => data.y as f32 * sensitivity * 400.0,
};

let factor = (1.0 + delta).clamp(0.8, 1.2);
Expand Down
1 change: 0 additions & 1 deletion packages/dioxus-native-dom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ keyboard-types = { workspace = true }

# Other dependencies
tracing = { workspace = true, optional = true }
rustc-hash = { workspace = true }
futures-util = { workspace = true }

[dev-dependencies]
Expand Down
65 changes: 53 additions & 12 deletions packages/dioxus-native-dom/src/dioxus_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::events::{
BlitzKeyboardData, NativeConverter, NativeFocusData, NativeFormData, NativePointerData,
NativeScrollData, NativeTouchData, NativeWheelData, NodeHandle,
};
use crate::mutation_writer::{DioxusState, MutationWriter};
use crate::mutation_writer::DioxusState;
use crate::qual_name;
use blitz_dom::{
Attribute, BaseDocument, DocGuard, DocGuardMut, Document, DocumentConfig, EventDriver,
Expand Down Expand Up @@ -33,7 +33,7 @@ fn get_dioxus_id(node: &Node) -> Option<ElementId> {
.iter()
.find(|attr| *attr.name.local == *"data-dioxus-id")
.and_then(|attr| attr.value.parse::<usize>().ok())
.map(ElementId)
.map(ElementId::from_raw)
}

/// Integrates [`BaseDocument`] from [`blitz-dom`](blitz_dom) with [`VirtualDom`] from [`dioxus-core`](dioxus_core)
Expand Down Expand Up @@ -141,11 +141,11 @@ impl DioxusDocument {

/// Run an initial build of the Dioxus vdom
pub fn initial_build(&mut self) {
let mut inner = self.inner.borrow_mut();
let mut writer = MutationWriter::new(&mut inner, &mut self.vdom_state);
self.vdom.rebuild(&mut writer);
drop(writer);
drop(inner);
// Mutations are buffered and only applied once the vdom has finished running. This means
// that the document is not borrowed while user code (which may access it) is running.
self.vdom.rebuild(&mut self.vdom_state.buffered_mutations);
self.vdom_state
.apply_buffered_mutations(&mut self.inner.borrow_mut());
self.flush_queued_mounted_events();
}

Expand Down Expand Up @@ -236,11 +236,12 @@ impl Document for DioxusDocument {
}
}

let mut inner = self.inner.borrow_mut();
let mut writer = MutationWriter::new(&mut inner, &mut self.vdom_state);
self.vdom.render_immediate(&mut writer);
drop(writer);
drop(inner);
// Mutations are buffered and only applied once the vdom has finished running. This means
// that the document is not borrowed while user code (which may access it) is running.
self.vdom
.render_immediate(&mut self.vdom_state.buffered_mutations);
self.vdom_state
.apply_buffered_mutations(&mut self.inner.borrow_mut());
self.flush_queued_mounted_events();

true
Expand Down Expand Up @@ -666,6 +667,46 @@ mod tests {
assert_eq!(counts[1], counts[2]);
}

#[test]
// Regression test for a panic. Tasks are polled while the vdom renders, at which point
// the document must not be borrowed.
fn task_polled_during_render_can_access_document() {
#[derive(Default)]
struct State {
focus: Cell<bool>,
mounted: RefCell<Option<Rc<MountedData>>>,
}

fn app() -> Element {
let state = consume_context::<Rc<State>>();
if state.focus.get() {
let mounted = state.mounted.borrow().clone().unwrap();
spawn(async move {
mounted.set_focus(true).await.unwrap();
mounted.get_client_rect().await.unwrap();
});
}
let focus = state.focus.get();
rsx!(input {
"data-focus": "{focus}",
onmounted: move |e| *state.mounted.borrow_mut() = Some(e.data()),
})
}

let state = Rc::new(State::default());
let vdom = VirtualDom::new(app).with_root_context(Rc::clone(&state));
let mut doc = DioxusDocument::new(vdom, DocumentConfig::default());
doc.initial_build();
state.focus.set(true);
rerender(&mut doc);
let inner = doc.inner.borrow();
let focussed = inner.get_node(inner.get_focussed_node_id().unwrap());
assert_eq!(
focussed.unwrap().attr(crate::LocalName::from("data-focus")),
Some("true")
);
}

#[test]
fn mounted_data_of_removed_element_reports_error() {
#[derive(Default)]
Expand Down
Loading
Loading