-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
Async component mounted/shown twice at same time #677
Comments
cc @developit i am not sure if this should be fixed in the template or the |
Just to mention that I'm facing the same issue, going to poke around to see what are the best steps to avoid this. |
A quick temporary hack setTimeout(()=>{this.setState({/*...*/}},0) |
Can confirm @shalomvolchok solution works, modifying the default handleRoute = e => {
setTimeout(() => {
this.setState({
currentUrl: e.url
})
}, 0)
}; |
I personally don't think we should be doing this hack, @developit can u check? |
cc: @lukeed |
the bit that causes the duplication is pretty important, it prevents the first client-side render from ripping out the prerendered DOM. Looks like we just need to synchronously flush via forceUpdate instead of setState. |
👋 just wanted to share that sadly the hack isn't really working as I thought, and keep getting the issue whenever I prerender it with |
@developit @ForsakenHarmony could I get more information on what do you think it's causing the issue here or some pointers on where to look? Maybe I can do some work on my own to solve this, as my current site still has this issue and haven't been able to work around it 😢 |
My preact-cli material template on Netlify renders duplicate divs as well. The said hack sort of ameliorated this on chrome -- not firefox. Is ditching the material goodies the best way to proceed at this point? |
The problem is or async component, more specifically the It's a workaround for a flash of no content Not sure why it would happen for prerendering though |
Hi, any update on this? Is there any way around this? And I mean anything that would allow me to publish this even if that has some downsides? |
well you can rename |
I followed @ForsakenHarmony's advice and renamed the routes directory? Code splitting is disabled but at least it works! 🎉 |
I ended up just turning off pre-rendering in my build until this is resolved. Not ideal, but it is better than the dupe.
|
@developit has a Suspense based fix for this. |
The confusing part is that folks are seeing this in Preact 8. My fix is specific to Preact X. |
@Pierre-Gilles But we still haven't gotten code splitting to work for preact 10 in cli@rc |
@ForsakenHarmony Oh I didn't know, thanks ! Any idea of a fix while waiting for |
cli@rc should be usable in it's current form, if you don't need async loading it could work for you |
I've been working with the
preact-cli
material template and it seems that a call tosetState
from withinhandleRoute
ofapp.js
causes the async wrapper'scomponentWillMount
to fire twice, resulting in the async component being duplicated on the screen. (next branch 3.0.0-next.14, but also observed in v2).This behavior can be seen with
npm run serve
after runningpreact-cli create material demo
, but the page needs to be scrolled to notice the duplication (I didn’t notice for some time).I also have a stripped down repo that minimally reproduces the behavior (without the router nor material design): https://github.com/shalomvolchok/async-route-duplication
In the stripped down repo the behavior is triggered by calling
setState
fromcomponentDidMount
(in any component higher than the async component).I had to dig for a while before I figured out where the double rendering was coming from, but it’s still not clear to me what the right solution would be to avoid/fix this. What do you all think?
The text was updated successfully, but these errors were encountered: