reactjs / React.NET

.NET library for JSX compilation and server-side rendering of React components
https://reactjs.net/
MIT License
2.3k stars 937 forks source link

Add ability to skip adding component to the list of components for @Html.React or @Html.ReactWithInit #1294

Open swcarter007 opened 2 years ago

swcarter007 commented 2 years ago

Thanks for filing a bug! To save time, if you're having trouble using the library, please check off the items you have tried. If you are just asking a question, skip right to the bottom.

I'm using these library versions:

Runtime environment:

Steps to reproduce

  1. Load component with @Html.ReactWithInit()
  2. Add @Html.ReactInitJavascript() lower on the page
  3. Component ReactDOM.hydrate method is added within the component within the DomContentLoaded right below the @Html.ReactWithInit() function, and again without the DCL next to to the @Html.ReactInitJavascript() declaration.

The issue is that the code is duplicated onto the page adding unnecessary page weight.

Expected change: Update @Html.React and @Html.ReactWithInit function to accept the skipLazyInit property that is exposed on the CreateComponent() function to allow adding a component without readding it later on.

Use cases: The simple use case is to avoid duplicate code, but the secondary use case would be to be able to hydrate a component earlier on the page than trying to hydrate the rest of the components lower on with the @Html.ReactInitJavascript() code.