DioxusLabs / DioxusLabs/dioxus

[SSG / Fullstack] document::Title renders before <!DOCTYPE html> in dx build --web --ssg --release

Open
#5,760 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**document::Title is being rendered before `` when using Static Site Generation (SSG)**

When using Static Site Generation and document::Title, both inside or outside routes, the title is being rendered outside the document as the very first element, even before ``, meaning the output is a malformed HTML file.

**Steps To Reproduce**

Steps to reproduce the behavior:

- Setup a fullstack project
- Setup SSG and Routes
- Use document::Title in a component
- Build the project with `dx build --web --ssg --release`

**Code example**

```Rust
fn main() {
dioxus::LaunchBuilder::new()
.with_cfg(server_only! {
ServeConfig::builder()
.incremental(
dioxus::server::IncrementalRendererConfig::new()
.static_dir(
std::env::current_exe()
.unwrap()
.parent()
.unwrap()
.join("public")
)
.clear_cache(false)
)
.enable_out_of_order_streaming()
})
.launch(App);
}

#[derive(Routable, Clone, PartialEq)]
enum Route {
#[route("/")]
ExampleRouteComponent,
}

#[server(endpoint = "static_routes", output = server_fn::codec::Json)]
async fn static_routes() -> Result, ServerFnError> {
Ok(Route::static_routes()
.iter()
.map(ToString::to_string)
.collect())
}

#[component]
fn App() -> Element {
rsx! {
// this one is going to be rendered as the very first element of the document, even before ""
document::Title { "Title of the app" }

Router:: {}
}
}

#[component]
fn ExampleRouteComponent() -> Element {
rsx! {
// also this one would be rendered as the very first element of the document
// document::Title { "Title of the app in Example Route Component" }
h1 { "Example Route Component" }
}
}

```

**Expected behavior**

The expected behavior is to have static HTML pages with the title tag rendered inside the head tag, not outside the document as the very first element.

**Environment:**

- Dioxus version: 0.7.10
- Rust version: 1.97.1
- OS info: Void Linux
- App platform: web

**Questionnaire**

I'm interested in fixing this myself but don't know where to start.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with a fullstack project using SSG, routes, document::Title, and `dx build --web --ssg --release`, then inspect the generated static HTML. Trace how the title is emitted during SSG and confirm completion when the title is inside the head after the doctype.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.