Skip to content
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

raw HTML in a component with SSR #2841

Closed
1 of 3 tasks
dmeijboom opened this issue Aug 23, 2022 · 2 comments · Fixed by #2842
Closed
1 of 3 tasks

raw HTML in a component with SSR #2841

dmeijboom opened this issue Aug 23, 2022 · 2 comments · Fixed by #2842
Labels
A-yew Area: The main yew crate feature-request A feature request

Comments

@dmeijboom
Copy link
Contributor

Problem
Using raw HTML in Yew is not so simple but thankfully the inner_html example provides a decent solution.
However, this doesn't work with SSR as the web_sys/gloo packages are not available in that context.

So, how can raw HTML be used with SSR?

Steps To Reproduce
Steps to reproduce the behavior:

  1. Use the inner_html example
  2. Switch to the SSR renderer
  3. Doesn't work

Expected behavior
The inner_html example was a workaround anyway so it would be good if there was an official way to handle raw HTML which also works with SSR.

Environment:

  • Yew version: master
  • Target, if relevant: any non-WASM target
  • Build tool, if relevant: trunk

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@dmeijboom dmeijboom added the bug label Aug 23, 2022
@dmeijboom dmeijboom changed the title SSR with raw HTML in a component raw HTML in a component with SSR Aug 23, 2022
@futursolo
Copy link
Member

Currently, inner_html is set with Html::VRef.
We cannot support this in SSR as we cannot instantiate web_sys::Node in non-browser environments.

However, this may change if #182 is implemented.

If you don't need the content in the inner html to be indexed by a search engine, you can delay the rendering logic that uses Web APIs with a use_effect hook so they are excluded from the server-side rendering process.

@dmeijboom
Copy link
Contributor Author

dmeijboom commented Aug 24, 2022

Currently, inner_html is set with Html::VRef. We cannot support this in SSR as we cannot instantiate web_sys::Node in non-browser environments.

However, this may change if #182 is implemented.

Cool, it seems like that's exactly what we need :)

If you don't need the content in the inner html to be indexed by a search engine, you can delay the rendering logic that uses Web APIs with a use_effect hook so they are excluded from the server-side rendering process.

It needs to be indexed, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew Area: The main yew crate feature-request A feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants