{"record":{"id":"e0d26553b648545a","repo":"DioxusLabs/dioxus","slug":"should-register-requestanimationframe-ok","errorCode":null,"errorMessage":"should register `requestAnimationFrame` OK","messagePattern":"should register `requestAnimationFrame` OK","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/web/src/history.rs","lineNumber":365,"sourceCode":"}\n\nimpl ScrollPosition {\n    pub(crate) fn of_window(window: &Window) -> Self {\n        Self {\n            x: window.scroll_x().unwrap_or_default(),\n            y: window.scroll_y().unwrap_or_default(),\n        }\n    }\n\n    pub(crate) fn scroll_to(&self, window: Window) {\n        let Self { x, y } = *self;\n        let f = Closure::wrap(\n            Box::new(move || window.scroll_to_with_x_and_y(x, y)) as Box<dyn FnMut()>\n        );\n        web_sys::window()\n            .expect(\"should be run in a context with a `Window` object (dioxus cannot be run from a web worker)\")\n            .request_animation_frame(&f.into_js_value().unchecked_into())\n            .expect(\"should register `requestAnimationFrame` OK\");\n    }\n}\n\npub(crate) fn replace_state_with_url(\n    history: &History,\n    value: &[f64; 2],\n    url: Option<&str>,\n) -> Result<(), JsValue> {\n    let position = js_sys::Array::new();\n    position.push(&JsValue::from(value[0]));\n    position.push(&JsValue::from(value[1]));\n    history.replace_state_with_url(&position, \"\", url)\n}\n\npub(crate) fn push_state_and_url(\n    history: &History,\n    value: &[f64; 2],\n    url: String,","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/393d190a801ccb441d41923e232289b4f8a5c669/packages/web/src/history.rs#L347-L383","documentation":"After re-obtaining the window, `scroll_to` registers its scroll callback with `.request_animation_frame(...).expect(\"should register `requestAnimationFrame` OK\")`. Registration fails when the API is unavailable or the context rejects it - rAF is missing in certain worker/sandboxed contexts and old embedded engines, or the document/iframe is being torn down - and the router panics while restoring scroll.","triggerScenarios":"Scroll restoration running where requestAnimationFrame does not exist (worker contexts, legacy webviews, restricted sandboxed iframes); a navigation racing page unload so rAF registration throws.","commonSituations":"SPA navigation firing as the user closes the tab; old embedded webview targets; test engines with partial browser APIs.","solutions":["Ensure navigation and scroll-restoration code runs on the live main thread with an active document","Cancel or debounce navigation-driven scroll work during page teardown","Upgrade the webview/browser so requestAnimationFrame is reliably available"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify rAF is available before navigation-driven scroll work\nlet raf_ok = web_sys::window()\n    .map(|w| js_sys::Reflect::get(w.as_ref(), &wasm_bindgen::JsValue::from_str(\"requestAnimationFrame\")).is_ok())\n    .unwrap_or(false);\nif !raf_ok { /* skip scroll restoration */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run navigation and scroll restoration on the live main thread with an active document","Cancel or debounce navigation-driven scroll work during page teardown so rAF registration cannot race unload","Upgrade embedded webviews and legacy engines where requestAnimationFrame is missing or unreliable"],"tags":["dioxus-web","router","requestanimationframe","scroll-restoration","panic"],"backgroundTag":null,"analyzedSha":"393d190a801ccb441d41923e232289b4f8a5c669","analyzedAt":"2026-08-16T11:27:45.815Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}