{"record":{"id":"421d10257365ea1a","repo":"zed-industries/zed","slug":"setting-canvas-text-direction-error","errorCode":null,"errorMessage":"setting Canvas text direction: {error:?}","messagePattern":"setting Canvas text direction: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_web/src/canvas_text.rs","lineNumber":65,"sourceCode":"        Ok(Self { canvas, context })\n    }\n\n    fn configure(&self, css_font: &str) -> Result<()> {\n        ensure!(!css_font.trim().is_empty(), \"Canvas text font is empty\");\n        // An invalid CSS font assignment is ignored by Canvas. Reset first so\n        // it cannot accidentally inherit the preceding request's font.\n        self.context.set_font(\"10px sans-serif\");\n        self.context.set_font(css_font);\n        self.context.set_text_align(\"left\");\n        self.context.set_text_baseline(\"alphabetic\");\n        self.context.set_fill_style_str(\"white\");\n        // web-sys does not expose direction on the offscreen 2D context.\n        let assigned = js_sys::Reflect::set(\n            self.context.as_ref(),\n            &JsValue::from_str(\"direction\"),\n            &JsValue::from_str(\"ltr\"),\n        )\n        .map_err(|error| anyhow!(\"setting Canvas text direction: {error:?}\"))?;\n        ensure!(assigned, \"Canvas text direction could not be set\");\n        Ok(())\n    }\n}\n\nfn with_canvas<T>(operation: impl FnOnce(&mut TextCanvas) -> Result<T>) -> Result<T> {\n    CANVAS.with(|canvas| {\n        let mut canvas = canvas\n            .try_borrow_mut()\n            .context(\"Canvas text renderer was called reentrantly\")?;\n        if canvas.is_none() {\n            *canvas = Some(TextCanvas::new()?);\n        }\n        operation(\n            canvas\n                .as_mut()\n                .context(\"Canvas text renderer is unavailable\")?,\n        )","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui_web/src/canvas_text.rs#L47-L83","documentation":"Thrown in TextCanvas::configure when the JS Reflect.set used to set `direction = 'ltr'` on the OffscreenCanvasRenderingContext2D (web-sys does not expose this property) throws a JsValue. This fires only if the browser rejects the property assignment — typically a detached/invalid 2D context or an unusual browser build — and makes the whole canvas text renderer unusable until a new canvas is created.","triggerScenarios":"Thrown at crates/gpui_web/src/canvas_text.rs:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry creating a fresh OffscreenCanvas with a new 2D context, since the existing context is likely in an invalid state","Fall back to skipping the direction assignment (Canvas defaults to 'ltr' direction) and continue rendering with the remaining configure steps","Fall back to a non-Canvas text path (e.g. DOM-based measurement/rasterization) if canvas text keeps failing","Log the JsValue error with its message (convert via js_sys::Error::from for details) to identify the browser-side cause"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}