-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Need a way to prevent component render on client side initial load #8017
Comments
@scsherwood Can't you just make the Google gpt request in componentDidMount, and then rerender with the results of this call. So react will finish 'rendering' the same markup as was sent from the server, and the ad request can happen separately after initial rendering is complete. |
@jblok the reason why we cant make it in componentDidMount is because:
|
|
Visually speaking, the app is present on first byte. The lifecycle on the client side ties up firing the gpt request.
The script is the bundled javascript (react, miscellaneous vendor scripts, app scripts, etc). GPT is loaded in the head of the document. Let me know if you have any more questions to clarify. Our goal is to visually render a full page with ads under ~2-3 seconds. |
We are trying to get out in front of the React render to get faster _Steven *_Sherwood * On Tue, Oct 25, 2016 at 11:18 AM, Jonathon Blok [email protected]
|
Another option may be to have an off-screen Then at the components This assumes you can determine when your ad service has finished rendering. |
Use state for this: class MyComponent extends Component {
constructor(props) {
super(props);
this.state = { hasMounted: false };
}
componentDidMount() {
this.setState({ hasMounted: true });
}
render() {
return (
<div>
<p>This text is rendered on the server.</p>
{this.state.hasMounted && <p>This text only appears after mounting.</p>}
</div>
);
}
} Generally we don't recommend |
Ill prepare a sample repo to illustrate situation |
Recently opened up a discussion with Kevin Lacker, and tried to reproduce our application on a smaller example repo, and was not able to reproduce the ads wipeout issue. https://github.com/roastlechon/react-component-wipeout-example My theory is that one of our libraries that we are using is causing a rerender, which causes the warning message for
I will continue to do some digging to determine what exactly is the library causing issues |
@scsherwood have you found the solution? I have exactly same issue - DFP ad disappears when React client app has been loaded |
@snegostup @roastlechon we have the same problem with GPT/AdSense ads. If we wait to show the first add until React is loaded (around 2 seconds) it destroys the viewability of that first ad. We need it to load the ad before React is loaded. That's really simple using SSR, but React wipes it out in the hydration phase. We are surprised there isn't any solution or workaround for this yet, so any insight is really welcomed :) |
@luisherranz we were able to diagnose and figure out that it was a hydration mismatch that occurred which wiped out the dom in hydration. GPT is able to load beforehand with the server side rendered markup and on hydration nothing is wiped out (after we fixed the issue with mismatch). |
@roastlechon thanks for your answer. Our error is:
We only render one So our mismatch is not really happening between our server and client code, but from our sever code, with the additional tags created by |
@roastlechon wait can you elaborate? Hydration should blow everything away, no? If your ad renders after server side render but before client render, why would the client hydration honor the ad and keep it there? @gaearon That makes sense but in this case, we want to suppress React client hydration totally as in our example, the html has updated between server & client render. |
@reywright it will keep it there if React renders exactly the same thing on both sides. For example: const { id } = this.props;
return (
<div
suppressHydrationWarning
dangerouslySetInnerHTML={{__html: `<div id="${id}"></div>`}}
/>
); Browser renders the ad even before this code loads, client-render-phase happens but doesn't touch the previously-created DOM nodes since that React DIV has the same properties. |
@eliseumds Thats fine, but the third party ads library might be adding multiple dom nodes, adding some dom attributes, etc. The Application has no way of knowing that beforehand, so its not possible to have the same markup rendered on the server side. @scsherwood any luck ? We facing the exact same issue, our ads library modifies the Dom just before React client side hydration. React 15 was fine with it, but React 16 goes and removes the Dom Nodes altogether. We don't want to wait till |
Another vote for the |
Note we generally don’t read discussions in closed issues. If this is still relevant please file a new issue with a more focused description of what you’re struggling with, and some demos. |
@gaearon wouldn't it be better to reopen this one? |
For anybody finding this thread and still having this problem, as of React 16.1.1 this very helpful comment on a related RFC seems to be exactly what you're looking for, similar to what @eliseumds was proposing. <div
dangerouslySetInnerHTML={{ __html: '' }}
suppressHydrationWarning
/>
|
For Ad performance in an isomorphic application we need React to avoid rendering an Ad Component containing an ad position div on the client initial load. Here is the following scenario:
If there is a way to conditionally stop React from rendering the ad position div on the client, we have not found it.
Seems like there needs to be a flag or method in the react lifecycle that can be used to prevent a component render on certain conditions.
The text was updated successfully, but these errors were encountered: