Skip to content

Commit

Permalink
Fix initial paint of web app (#5633)
Browse files Browse the repository at this point in the history
* Broke in #5631 (for _some_ apps)
  • Loading branch information
emilk authored Jan 23, 2025
1 parent edbf4e8 commit bc5f908
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ impl ResizeObserverContext {
let runner_ref = runner_ref.clone();
move |entries: js_sys::Array| {
if DEBUG_RESIZE {
// log::info!("ResizeObserverContext callback");
log::info!("ResizeObserverContext callback");
}
// Only call the wrapped closure if the egui code has not panicked
if let Some(mut runner_lock) = runner_ref.try_lock() {
Expand Down Expand Up @@ -919,6 +919,8 @@ impl ResizeObserverContext {
if let Err(err) = runner_ref.request_animation_frame() {
log::error!("{}", super::string_from_js_value(&err));
};
} else {
log::warn!("ResizeObserverContext callback: failed to lock runner");
}
}
}) as Box<dyn FnMut(js_sys::Array)>);
Expand Down
17 changes: 10 additions & 7 deletions crates/eframe/src/web/web_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,27 @@ impl WebRunner {
canvas.style().set_property("outline", "none")?;
}

let text_agent = TextAgent::attach(self)?;
{
// First set up the app runner:
let text_agent = TextAgent::attach(self)?;
let app_runner =
AppRunner::new(canvas.clone(), web_options, app_creator, text_agent).await?;
self.app_runner.replace(Some(app_runner));
}

{
let resize_observer = events::ResizeObserverContext::new(self)?;

// This will (eventually) result in a `request_animation_frame` to start the render loop.
// Properly size the canvas. Will also call `self.request_animation_frame()` (eventually)
resize_observer.observe(&canvas);

self.resize_observer.replace(Some(resize_observer));
}

{
let app_runner = AppRunner::new(canvas, web_options, app_creator, text_agent).await?;
self.app_runner.replace(Some(app_runner));
}

events::install_event_handlers(self)?;

log::info!("event handlers installed.");

Ok(())
}

Expand Down

0 comments on commit bc5f908

Please sign in to comment.