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

Improve server side only rendering #497

wants to merge 13 commits into
base: master


None yet
2 participants

gazab commented Jan 15, 2018

This PR fixes two issues with rendering server side ONLY components:

  • Component containers are no longer rendered
  • @Html.ReactInitJavaScript() no longer outputs JavaScript hydrating the component

For example, consider the following code:
@Html.React("HelloWorld", Model, serverOnly: true)

Before the fix this resulted in the following HTML:
<div id="react-container123"><h1>Hello world!</h1></div>

And Html.ReactInitJavaScript() rendered:
<script>ReactDOM.hydrate(React.createElement(HelloWorld, {"name":"example"}), document.getElementById("react-container123"));</script>

despite the serverOnly = true argument

After this fix the component will be rendered like this:
<h1>Hello world!</h1>
and ReactInitJavaScript() won't render anything at all for this component.

This should fix #340


This comment has been minimized.


gazab commented Jan 15, 2018

I'll rebase tomorrow


Thanks for the PR! At first glance this looks good..need to test this on my workstation before merging.

It looks like the line endings changed in one of the tests, and some lock files were committed. Can you please remove those changes?

gazab added some commits Jan 16, 2018


This comment has been minimized.


gazab commented Jan 16, 2018

@dustinsoftware fixed! If you wonder why I changed some of the test assertions it's because they made more sense that way. Passing true to either clientOnly or serverOnly, but not both at the same time.

Ideally, maybe those parameters should be joined to an enum or something instead. I.e enum RenderMode: ClientAndServer, ClientOnly, ServerOnly.

I didn't want to introduce too big changes though so I left it like it was.


Looks good to me. There are a few code style nits but I can fix those after merging.

dustinsoftware added a commit that referenced this pull request Jan 21, 2018


This comment has been minimized.


dustinsoftware commented Jan 21, 2018


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment