{"record":{"id":"415b455550806210","repo":"leptos-rs/leptos","slug":"queuemicrotask-not-available","errorCode":null,"errorMessage":"queueMicrotask not available","messagePattern":"queueMicrotask not available","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tachys/src/renderer/dom.rs","lineNumber":53,"sourceCode":"pub type CssStyleDeclaration = web_sys::CssStyleDeclaration;\npub type TemplateElement = web_sys::HtmlTemplateElement;\n\n/// A microtask is a short function which will run after the current task has\n/// completed its work and when there is no other code waiting to be run before\n/// control of the execution context is returned to the browser's event loop.\n///\n/// Microtasks are especially useful for libraries and frameworks that need\n/// to perform final cleanup or other just-before-rendering tasks.\n///\n/// [MDN queueMicrotask](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask)\npub fn queue_microtask(task: impl FnOnce() + 'static) {\n    use js_sys::{Function, Reflect};\n\n    let task = Closure::once_into_js(task);\n    let window = window();\n    let queue_microtask =\n        Reflect::get(&window, &JsValue::from_str(\"queueMicrotask\"))\n            .expect(\"queueMicrotask not available\");\n    let queue_microtask = queue_microtask.unchecked_into::<Function>();\n    _ = queue_microtask.call1(&JsValue::UNDEFINED, &task);\n}\n\nfn queue(fun: Box<dyn FnOnce()>) {\n    use std::cell::{Cell, RefCell};\n\n    thread_local! {\n        static PENDING: Cell<bool> = const { Cell::new(false) };\n        static QUEUE: RefCell<Vec<Box<dyn FnOnce()>>> = RefCell::new(Vec::new());\n    }\n\n    QUEUE.with_borrow_mut(|q| q.push(fun));\n    if !PENDING.replace(true) {\n        queue_microtask(|| {\n            let tasks = QUEUE.take();\n            for task in tasks {\n                task();","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/tachys/src/renderer/dom.rs#L35-L71","documentation":"DomRenderer::queue_microtask reads window.queueMicrotask via reflection and panics if the property is absent. The library expects a standard browser environment; throwing here flags a runtime where microtask scheduling is unavailable.","triggerScenarios":"Running the WASM DOM renderer in a non-browser JS environment (Node without jsdom/polyfills, minimal JS runtimes, service workers without window, outdated embedded webviews) where window.queueMicrotask is undefined.","commonSituations":"SSR/hydration tests running leptos DOM code under Node; custom wasm test harnesses; old WebKit-based webviews lacking queueMicrotask; bundler configs shimming window incompletely.","solutions":["Run in a real browser or polyfill queueMicrotask (e.g. via jsdom in tests or a core-js/microtask shim)","For SSR, ensure the DOM renderer is not invoked server-side (use the appropriate renderer for the platform)","Use Promise.resolve().then-based polyfill assigned onto globalThis/window before app boot","Upgrade the webview/runtime to one supporting queueMicrotask"],"exampleFix":"// before\n// Node test without polyfill -> panics\n// after\n// polyfill.mjs loaded first\nglobalThis.queueMicrotask ??= (fn) => Promise.resolve().then(fn);\n","handlingStrategy":"fallback","validationCode":"let has_microtask = js_sys::Reflect::get(&web_sys::window().unwrap(), &wasm_bindgen::JsValue::from_str(\"queueMicrotask\"))\n    .map(|v| !v.is_undefined()).unwrap_or(false);","typeGuard":null,"tryCatchPattern":"// install a polyfill fallback before app boot:\nif !has_microtask() {\n    js_sys::eval(\"globalThis.queueMicrotask = (f) => Promise.resolve().then(f);\").unwrap();\n}","preventionTips":["Load polyfills (queueMicrotask, etc.) before mounting the app","For Node tests, use a jsdom-based harness or install the polyfill in test setup","Avoid running the DOM renderer outside browsers (use SSR renderer server-side)","Pin/upgrade webviews to versions supporting queueMicrotask"],"tags":["wasm","browser","polyfill","panic"],"backgroundTag":"missing-browser-api","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}