-
-
Notifications
You must be signed in to change notification settings - Fork 990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document Level Tags Are Applied In Reverse Order #3756
Comments
Dioxus mounts nodes in a reverse order here because of the template diffing optimization system. Outside of a single rsx block, I'm not sure there is a clear order for head elements. Head elements could be loaded asynchronously based on the result of a resource. A script that loads immediately will be inserted before a script that loads asynchronously regardless of the depth first order of the script elements in the tree. You can use imports that don't rely on the order of script tags. es6 imports seem like a much more predictable way to handle dependencies: use dioxus::prelude::*;
static HIGHLIGHT: Asset = asset!("/assets/highlight/es/highlight.min.js");
static RUST: Asset = asset!("/assets/highlight/es/languages/rust.min.js");
fn app() -> Element {
rsx! {
document::Script {
type: "module",
r#"import hljs from "{HIGHLIGHT}";
import rust from "{RUST}";
hljs.registerLanguage('rust', rust);
setTimeout(() => {{
hljs.highlightAll();
}}, 1000);"#
}
pre {
code {
class: "language-rust",
"fn main() {{\nprintln!(\"Hello, world!\");\n}}"
}
}
}
}
fn main() {
dioxus::launch(app)
} |
Thanks for the information and solution! That makes sense. Reverse order in the head is an unfortunate consequence. This should probably be documented somewhere. You're solution of using a module should also probably be documented for such cases. For completeness, if you decide to use this example, a timeout is not needed since modules are deferred and a style is needed: use dioxus::prelude::*;
static HIGHLIGHT: Asset = asset!("/assets/highlight/es/highlight.min.js");
static RUST: Asset = asset!("/assets/highlight/es/languages/rust.min.js");
static STYLE: Asset = asset!("/assets/highlight/styles/atom-one-dark.css");
fn app() -> Element {
rsx! {
document::Link { rel: "stylesheet", href: STYLE }
document::Script {
type: "module",
r#"import hljs from "{HIGHLIGHT}";
import rust from "{RUST}";
hljs.registerLanguage('rust', rust);
hljs.highlightAll();"#
}
pre {
code {
class: "language-rust",
"fn main() {{\nprintln!(\"Hello, world!\");\n}}"
}
}
}
}
fn main() {
dioxus::launch(app)
} I can make a pr to add this to the docs if you'd like. |
That would be great, thanks! |
I created a PR #3771 This also lead me to create DioxusLabs/docsite#448 While this issue is fresh in your mind, It may have some relation to #3757 |
Problem
Document level tags do not respect order. E.g. for
In browser:
Also worth noting that muli-line str
r#" "#
breaksdx fmt
.Expected behavior
Screenshots
Environment:
Questionnaire
I'm interested in fixing this myself but don't know where to start.
The text was updated successfully, but these errors were encountered: