Move the document trait into a separate crate (#3035)
* add a default head method through eval * remove the old document trait * implement document for each platform * pull out document into a dedicated crate to cut down on shared dependencies --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
2b219c826c
commit
519ec9d294
91 files changed
+1113
-1044
No files matched your search
@@ -4,9 +4,8 @@
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
use dioxus_lib::{html::document::*, prelude::*};
|
||||
use dioxus_lib::{document::*, prelude::*};
|
||||
use dioxus_ssr::Renderer;
|
||||
use generational_box::GenerationalBox;
|
||||
use once_cell::sync::Lazy;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
@@ -71,8 +70,8 @@ impl ServerDocument {
|
||||
}
|
||||
|
||||
impl Document for ServerDocument {
|
||||
fn new_evaluator(&self, js: String) -> GenerationalBox<Box<dyn Evaluator>> {
|
||||
NoOpDocument.new_evaluator(js)
|
||||
fn eval(&self, js: String) -> Eval {
|
||||
NoOpDocument.eval(js)
|
||||
}
|
||||
|
||||
fn set_title(&self, title: String) {
|
||||
@@ -151,7 +150,7 @@ impl Document for ServerDocument {
|
||||
}
|
||||
}
|
||||
|
||||
fn create_link(&self, props: head::LinkProps) {
|
||||
fn create_link(&self, props: LinkProps) {
|
||||
self.warn_if_streaming();
|
||||
self.serialize_for_hydration();
|
||||
self.0.borrow_mut().link.push(rsx! {
|
||||
@@ -173,8 +172,4 @@ impl Document for ServerDocument {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#![allow(unused)]
|
||||
//! On the client, we use the [`WebDocument`] implementation to render the head for any elements that were not rendered on the server.
|
||||
|
||||
use dioxus_lib::events::Document;
|
||||
use dioxus_lib::document::*;
|
||||
use dioxus_web::WebDocument;
|
||||
|
||||
fn head_element_written_on_server() -> bool {
|
||||
@@ -15,11 +15,8 @@ fn head_element_written_on_server() -> bool {
|
||||
pub struct FullstackWebDocument;
|
||||
|
||||
impl Document for FullstackWebDocument {
|
||||
fn new_evaluator(
|
||||
&self,
|
||||
js: String,
|
||||
) -> generational_box::GenerationalBox<Box<dyn dioxus_lib::prelude::document::Evaluator>> {
|
||||
WebDocument.new_evaluator(js)
|
||||
fn eval(&self, js: String) -> Eval {
|
||||
WebDocument.eval(js)
|
||||
}
|
||||
|
||||
fn set_title(&self, title: String) {
|
||||
@@ -29,35 +26,31 @@ impl Document for FullstackWebDocument {
|
||||
WebDocument.set_title(title);
|
||||
}
|
||||
|
||||
fn create_meta(&self, props: dioxus_lib::prelude::MetaProps) {
|
||||
fn create_meta(&self, props: MetaProps) {
|
||||
if head_element_written_on_server() {
|
||||
return;
|
||||
}
|
||||
WebDocument.create_meta(props);
|
||||
}
|
||||
|
||||
fn create_script(&self, props: dioxus_lib::prelude::ScriptProps) {
|
||||
fn create_script(&self, props: ScriptProps) {
|
||||
if head_element_written_on_server() {
|
||||
return;
|
||||
}
|
||||
WebDocument.create_script(props);
|
||||
}
|
||||
|
||||
fn create_style(&self, props: dioxus_lib::prelude::StyleProps) {
|
||||
fn create_style(&self, props: StyleProps) {
|
||||
if head_element_written_on_server() {
|
||||
return;
|
||||
}
|
||||
WebDocument.create_style(props);
|
||||
}
|
||||
|
||||
fn create_link(&self, props: dioxus_lib::prelude::head::LinkProps) {
|
||||
fn create_link(&self, props: LinkProps) {
|
||||
if head_element_written_on_server() {
|
||||
return;
|
||||
}
|
||||
WebDocument.create_link(props);
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user