Skip to content

Javascript console warning when Server-side rendering is disabled #632

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

Closed
kpkozak opened this issue Nov 28, 2018 · 2 comments · Fixed by #636
Closed

Javascript console warning when Server-side rendering is disabled #632

kpkozak opened this issue Nov 28, 2018 · 2 comments · Fixed by #636
Labels

Comments

@kpkozak
Copy link
Contributor

kpkozak commented Nov 28, 2018

When Server Side rendering is disabled via config (ReactSiteConfiguration.DisableServerSideRendering()), components that are not explicitly marked as client-only throws an error to Javascript console, similar to this:

Warning: Expected server HTML to contain a matching <div> in <div>.

The possible case is that while rendering JavaScript for ReactComponents, it is checked only if the component is ClientOnly. If it's not , hydrate is used instead of render.
I think that hydrate should be used only if component isn't client only and server-side rendering was not disabled via config.

@dustinsoftware
Copy link
Member

What version are you on? There was a similar bug a while ago that has since been fixed..

@kpkozak
Copy link
Contributor Author

kpkozak commented Nov 30, 2018

The latest one, 3.4.1
I've found indeed similar thing - #521. It is connected, but I think a different one.

ReactComponent is checking if the component is client only (that means, if clientOnly parameter of @Html.React(... was set to true. However, it is not checking if server side rendering wasn't completely disabled via config (which effectively means that all components are client only, regardless of clientOnly flag). That scenario should also be covered there. So, in ReactComponent.cs, instead of

writer.Write(this.ClientOnly ? "ReactDOM.render(" : "ReactDOM.hydrate(");

it should be more like

writer.Write(!_configuration.UseServerSideRendering || this.ClientOnly ? "ReactDOM.render(" : "ReactDOM.hydrate(");

My use case was that I configured ReactJS.Net to disable SSR in debug mode to speed up and ease development, and leave it enabled when in release mode or deployed to any non-development environment, but this caused errors listed above on dev machine.

I'll try to do a PR during a weekend if I find some time for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants