fix(web): sync canvaskit size before first paint

This commit is contained in:
Kayshen-X 2026-06-19 01:30:43 +08:00
parent a1efac6712
commit a9ba127ec1
2 changed files with 24 additions and 1 deletions

View file

@ -796,7 +796,11 @@ pub async fn mount_ck(canvas_id: String) -> Result<(), JsValue> {
canvas: canvas.clone(),
a11y,
}));
inner.borrow_mut().repaint();
{
let mut b = inner.borrow_mut();
let _ = b.resize_to_window(&window)?;
b.repaint();
}
crate::web_fonts::drain_font_requests(&inner);
// Populate the chat model picker from the daemon's `/api/ai/models`

View file

@ -28,6 +28,25 @@ fn canvaskit_mount_listens_for_window_resize() {
);
}
#[test]
fn canvaskit_mount_syncs_window_size_before_first_repaint() {
let source = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/src/canvaskit.rs"))
.expect("canvaskit source is readable");
let start = source
.find("let inner = Rc::new(RefCell::new(CkInner")
.expect("mount creates CkInner");
let first_repaint = source[start..]
.find("repaint();")
.map(|idx| start + idx)
.expect("mount performs an initial repaint");
let initial_mount = &source[start..first_repaint];
assert!(
initial_mount.contains("resize_to_window(&window)"),
"CanvasKit mount must sync the backend to the current browser viewport before the first repaint"
);
}
#[test]
fn canvaskit_mount_does_not_panic_if_a11y_mirror_borrow_is_busy() {
let source = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/src/canvaskit.rs"))