-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add means to opt out of ssr partially or completely (#12)
* feat: add a component that excludes its children from ssr * feat: allow opting out of ssr based on request context
- Loading branch information
Showing
9 changed files
with
101 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::ops::Deref; | ||
|
||
use yew::html::ChildrenProps; | ||
use yew::prelude::*; | ||
|
||
/// A component that automatically excludes its children from server-side rendering. | ||
#[function_component] | ||
pub fn ClientOnly(props: &ChildrenProps) -> Html { | ||
let should_render = use_state(|| false); | ||
|
||
// Effects are only run on the client side. | ||
{ | ||
use_effect_with_deps( | ||
|should_render_setter| { | ||
should_render_setter.set(true); | ||
}, | ||
should_render.setter(), | ||
); | ||
} | ||
|
||
match should_render.deref() { | ||
true => html! {<>{props.children.clone()}</>}, | ||
false => Html::default(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod client_only; | ||
|
||
pub use client_only::ClientOnly; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters