Skip to content

Commit

Permalink
moved SpecialVTagKind to feat_ssr, improved its description
Browse files Browse the repository at this point in the history
  • Loading branch information
its-the-shrimp committed Aug 20, 2023
1 parent 437d7d9 commit 3bb737a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
3 changes: 2 additions & 1 deletion packages/yew/src/html/component/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,14 @@ mod feat_ssr {
use std::fmt::Write;

use super::*;
use crate::feat_ssr::SpecialVTagKind;
use crate::html::component::lifecycle::{
ComponentRenderState, CreateRunner, DestroyRunner, RenderRunner,
};
use crate::platform::fmt::BufWriter;
use crate::platform::pinned::oneshot;
use crate::scheduler;
use crate::virtual_dom::Collectable;
use crate::{scheduler, SpecialVTagKind};

impl<COMP: BaseComponent> Scope<COMP> {
pub(crate) async fn render_into_stream(
Expand Down
44 changes: 25 additions & 19 deletions packages/yew/src/server_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,33 @@ use crate::html::{BaseComponent, Scope};
use crate::platform::fmt::BufStream;
use crate::platform::{LocalHandle, Runtime};

/// Passed top-down as context for `render_into_stream` functions to know the current innermost
/// VTag kind to apply appropriate text escaping.
#[cfg(feature = "ssr")]
#[derive(Default, Clone, Copy)]
pub(crate) enum SpecialVTagKind {
Style, // <style> tag
Script, // <script> tag
#[default]
Other,
}
pub(crate) mod feat_ssr {
/// Passed top-down as context for `render_into_stream` functions to know the current innermost
/// `VTag` kind to apply appropriate text escaping.
/// Right now this is used to make `VText` nodes aware of their environment and correctly
/// escape their contents when rendering them during SSR.
#[derive(Default, Clone, Copy)]
pub(crate) enum SpecialVTagKind {
/// <style> tag
Style,
/// <script> tag
Script,
#[default]
/// any other tag
Other,
}

#[cfg(feature = "ssr")]
impl<T: AsRef<str>> From<T> for SpecialVTagKind {
fn from(value: T) -> Self {
let value = value.as_ref();
if value.eq_ignore_ascii_case("style") {
Self::Style
} else if value.eq_ignore_ascii_case("script") {
Self::Script
} else {
Self::Other
impl<T: AsRef<str>> From<T> for SpecialVTagKind {
fn from(value: T) -> Self {
let value = value.as_ref();
if value.eq_ignore_ascii_case("style") {
Self::Style
} else if value.eq_ignore_ascii_case("script") {
Self::Script
} else {
Self::Other
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/yew/src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::html::Scoped;
#[cfg(any(feature = "ssr", feature = "csr"))]
use crate::html::{AnyScope, Scope};
#[cfg(feature = "ssr")]
use crate::{platform::fmt::BufWriter, SpecialVTagKind};
use crate::{feat_ssr::SpecialVTagKind, platform::fmt::BufWriter};

/// A virtual component.
pub struct VComp {
Expand Down Expand Up @@ -256,7 +256,6 @@ impl<COMP: BaseComponent> fmt::Debug for VChild<COMP> {
mod feat_ssr {
use super::*;
use crate::html::AnyScope;
use crate::SpecialVTagKind;

impl VComp {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ mod feat_ssr {
use futures::{join, pin_mut, poll, FutureExt};

use super::*;
use crate::feat_ssr::SpecialVTagKind;
use crate::html::AnyScope;
use crate::platform::fmt::{self, BufWriter};
use crate::SpecialVTagKind;

impl VList {
pub(crate) async fn render_into_stream(
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ mod feat_ssr {
use futures::future::{FutureExt, LocalBoxFuture};

use super::*;
use crate::feat_ssr::SpecialVTagKind;
use crate::html::AnyScope;
use crate::platform::fmt::BufWriter;
use crate::SpecialVTagKind;

impl VNode {
pub(crate) fn render_into_stream<'a>(
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vsuspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ impl VSuspense {
#[cfg(feature = "ssr")]
mod feat_ssr {
use super::*;
use crate::feat_ssr::SpecialVTagKind;
use crate::html::AnyScope;
use crate::platform::fmt::BufWriter;
use crate::virtual_dom::Collectable;
use crate::SpecialVTagKind;

impl VSuspense {
pub(crate) async fn render_into_stream(
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ mod feat_ssr {
use std::fmt::Write;

use super::*;
use crate::feat_ssr::SpecialVTagKind;
use crate::html::AnyScope;
use crate::platform::fmt::BufWriter;
use crate::virtual_dom::VText;
use crate::SpecialVTagKind;

// Elements that cannot have any child elements.
static VOID_ELEMENTS: &[&str; 14] = &[
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vtext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ mod feat_ssr {
use std::fmt::Write;

use super::*;
use crate::feat_ssr::SpecialVTagKind;
use crate::html::AnyScope;
use crate::platform::fmt::BufWriter;
use crate::SpecialVTagKind;

impl VText {
pub(crate) async fn render_into_stream(
Expand Down

0 comments on commit 3bb737a

Please sign in to comment.