{"record":{"id":"6c5e1327f5cc89e5","repo":"DioxusLabs/dioxus","slug":"failed-to-read-index-html-from-public-directory","errorCode":null,"errorMessage":"Failed to read index.html from public directory","messagePattern":"Failed to read index\\.html from public directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/fullstack-server/src/config.rs","lineNumber":61,"sourceCode":"    /// Create a new ServeConfig with incremental static generation disabled and the default index.html settings.\n    pub fn builder() -> Self {\n        Self::new()\n    }\n\n    /// Create a new ServeConfig with incremental static generation disabled and the default index.html settings\n    ///\n    /// This will automatically use the `index.html` file in the `/public` directory if it exists.\n    /// The `/public` folder is meant located next to the current executable. If no `index.html` file is found,\n    /// a default index.html will be used, which will not include any JavaScript or WASM initialization code.\n    ///\n    /// To provide an alternate `index.html`, you can use `with_index_html` method instead.\n    pub fn new() -> Self {\n        let index = if let Some(public_path) = crate::public_path() {\n            let index_html_path = public_path.join(\"index.html\");\n\n            if index_html_path.exists() {\n                let index_html = std::fs::read_to_string(index_html_path)\n                    .expect(\"Failed to read index.html from public directory\");\n\n                IndexHtml::new(&index_html, \"main\")\n                    .expect(\"Failed to parse index.html from public directory\")\n            } else {\n                IndexHtml::ssr_only()\n            }\n        } else {\n            tracing::warn!(\n                \"Cannot identify public directory, using default index.html. If you need client-side scripts (like JS + WASM), please provide an explicit public directory.\"\n            );\n            IndexHtml::ssr_only()\n        };\n\n        Self {\n            index,\n            incremental: None,\n            context_providers: Default::default(),\n            streaming_mode: StreamingMode::default(),","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/393d190a801ccb441d41923e232289b4f8a5c669/packages/fullstack-server/src/config.rs#L43-L79","documentation":"When the fullstack server boots its RenderedServerConfig it looks for index.html under the public directory; if the file exists but read_to_string fails (invalid UTF-8 bytes or a read error like permissions), it panics with this expect during server construction.","triggerScenarios":"A public/index.html that exists but is not valid UTF-8 (saved in a legacy codepage or containing stray binary bytes) or is unreadable by the server process when RenderedServerConfig::new() runs.","commonSituations":"Templates edited on Windows and saved as latin-1/ANSI; binary garbage pasted into index.html; container images where the public dir is root-owned while the server runs as another user.","solutions":["Re-save public/index.html as UTF-8","Fix permissions/ownership so the server process can read the file (chown/chmod in containers)","If the file is not meant to be served, remove or rename it so the SSR-only default index is used"],"exampleFix":"# before: file saved as latin-1 with invalid bytes\n# fix: convert encoding to UTF-8\niconv -f latin1 -t utf-8 public/index.html -o public/index.html","handlingStrategy":"validation","validationCode":"// Validate index.html before starting the fullstack server\nlet path = std::path::Path::new(\"public/index.html\");\nif path.exists() {\n    let bytes = std::fs::read(path).expect(\"read index.html\");\n    std::str::from_utf8(&bytes).expect(\"index.html must be UTF-8\");\n}","typeGuard":"fn is_utf8_file(p: &std::path::Path) -> bool {\n    std::fs::read(p).map(|b| std::str::from_utf8(&b).is_ok()).unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Save all HTML assets as UTF-8, especially when editing on Windows","In containers, ensure the public dir is readable by the server user","CI lint: validate that every file in public/ decodes as UTF-8 before deploy"],"tags":["fullstack","server","index-html","utf8","io","runtime"],"backgroundTag":null,"analyzedSha":"393d190a801ccb441d41923e232289b4f8a5c669","analyzedAt":"2026-08-16T11:27:45.815Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}