Skip to content

Commit 85291f3

Browse files
committed
fix: handle absent body and rust-link as an error
If there's neither a body element, nor a link rel="rust" element, then there's no way to guess a location for inserting the wasm initializer. Instead of silently ignoring, or adding a body element ourselves, we raise this as an error. Closes #791
1 parent bcbf617 commit 85291f3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/pipelines/rust/output.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
config::{CrossOrigin, RtcBuild},
55
pipelines::rust::{sri::SriBuilder, RustAppType},
66
};
7+
use anyhow::bail;
78
use std::collections::HashMap;
89
use std::sync::Arc;
910

@@ -102,7 +103,14 @@ impl RustAppOutput {
102103

103104
match self.id {
104105
Some(id) => dom.replace_with_html(&trunk_id_selector(id), &script)?,
105-
None => dom.append_html(body, &script)?,
106+
None => {
107+
if dom.len(&body)? == 0 {
108+
bail!(
109+
r#"Document has neither a <link data-trunk rel="rust"/> nor a <body>. Either one must be present."#
110+
);
111+
}
112+
dom.append_html(body, &script)?
113+
}
106114
}
107115

108116
Ok(())

0 commit comments

Comments
 (0)