-
Notifications
You must be signed in to change notification settings - Fork 393
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
weird element placement behavior #214
Comments
Hi @IlhamWahabiGX. It is hard to tell what exactly cause this behaviour I haven't seen anything like that before, can you try to construct minimal example where it is possible to reproduce bug. It is obvious that there is unclosed html tag somewhere, but I'm not sure why it happens. |
This is also happening for me. I'm trying to narrow down where the unclosed tag could be. It's been rough going so far for two reasons:
|
Update: As far as I can tell, in debugging this, these snapshots will never hydrate correctly for me. Here's what I did to get to this conclusion:
Making these changes allowed me to more easily debug, but more importantly it uses What I found was that, there's basically nothing I can do to get the app to correctly hydrate. Stepping through the hydration process, it will inevitably find Here's what I mean: const App = () => (
<nav>
<figure>Hello</figure>
<Foo />
</nav>
); Hydration fails when it hits There are other, more basic hydration issues though. For example, I had to disable class and attribute sorting which are enabled by default in the options for So all of this is concerning as it appears hydration is does not work at all in anything non-trial. However, the real question is: Why does this result in broken HTML output when hydrate throws? Every one of my pages look perfect except for the home page. None of them hydrate correctly, but they all look fine. And they are all fully interactive even with the hydration errors. I haven't looked into it, but I assume that React falls back to For example, if I load the home page, navigate to another route, and then navigate back home, everything renders correctly. React is continuing the relay even though the baton got dropped. I still haven't figured this out. However, since hydration seems infeasible in the current implementation, I can fix this by simply changing to But at least there's the crawler benefits. NOTE: I should probably mention I'm also using Redux, and have all the state snapshot stuff setup (and it appears to work). |
@bfricka it can happen that hydration issue and unclosed tag are not connected. Can you post what hydration exception saying?
Not sure what you mean. Hydration works in this example, which is pretty similar to what you post. We can create example with the same versions of libs as yours (React etc). |
That's a poor example b/c it's using custom scripts in a non-ejected Currently working on some deeper debugging. I used create-react-app + the steps I outlined above to prove that there are lots of hydration warnings for trivial examples, but none of them have hit what I believe to be the more critical failure points: The crucial thing I think I'm seeing is in But basically, when if (!tryHydrate(fiber, nextInstance)) {
// If we can't hydrate this instance let's try the next one.
// We use this as a heuristic. It's based on intuition and not data so it
// might be flawed or unnecessary.
nextInstance = getNextHydratableSibling(firstAttemptedInstance);
if (!nextInstance || !tryHydrate(fiber, nextInstance)) {
// Nothing to hydrate. Make it an insertion.
insertNonHydratedInstance(hydrationParentFiber, fiber);
isHydrating = false;
hydrationParentFiber = fiber;
return;
}
// We matched the next one, we'll now assume that the first one was
// superfluous and we'll delete it. Since we can't eagerly delete it
// we'll have to schedule a deletion. To do that, this node needs a dummy
// fiber associated with it.
deleteHydratableInstance(hydrationParentFiber, firstAttemptedInstance);
}
hydrationParentFiber = fiber;
nextHydratableInstance = getFirstHydratableChild(nextInstance);
} The real question is why this discrepancy. I have a few hypotheses to try and I'll report back if I find anything useful. Edit: Basically, if, in |
You want to say if I will eject and replace production with development I will start to see hydration errors - they exist, but I don't see it because of production build instead of development. I will try. |
I found the source of my particular issue. I use react-i18next for translations, and this will check to see if translations are loaded before rendering its children. I followed the render loop to the problem area and found that when it gets to this part of the tree and calls the render function on I found that all the hydration warnings I mentioned previously are still going to be there, but hydrate itself doesn't fail unless |
You can save translations with |
@bfricka you are totally right about |
Yeah, I think we're on the same page. It wasn't until I stepped through everything that I saw that there are different issues associated w/ hydration. Some of these issues are minor and only throw warnings, while hydration continues (className / attribute order, text content changes, etc) successfully. Other issues, like those caused by dynamic content mismatches (i18n, and I presume redux state issues), will cause hydration to bail. Thanks for engaging in the conversation here. I'm not sure if this addresses OP's question or not, but I would presume it has something to do w/ dynamic state missing on initial reconciliation. Thanks for the Thanks again. |
I'm not sure which i18n scheme do you use, but if it is based on url e.g.
or
you can capture required translation at build time, the same way you do with Redux store. |
Closing because not enough information for investigation. @IlhamWahabiGX feel free to reopen. |
I'm having the same issue with hydration and an ejected create-react-app project. I'll try to get a simpler example emulating this. Is there any other issues that we can link here? |
Hi, I had this kind of issue. I think it is related to your issue, my fix may help. The reason was an incoherent pre-rendered html with the first client side render. They both should render the same tree (in order to hydrate correctly). In my case, the render was different on the client side because of a different state set in the componentWillMount method. Replacing it with the componentDidMount method resolved the issue because the first render is now coherent with the pre-rendered html. Hope this helps (it may be documented in react-snap docs) |
after using react snap (there is no problem before), instead got this normal result:
![before](https://camo.githubusercontent.com/80711b90f079a7f1af136560cc5108620d2b50b1b08d3d820a633e61bcf384fd/68747470733a2f2f7075752e73682f415a6357622f653934373961353532312e706e67)
with this normal structure
![before](https://camo.githubusercontent.com/5a4fc59890077fec783ff2cfe657d5d407e6f53b7879ac62ac03eebe30affb53/68747470733a2f2f7075752e73682f415a6355382f316434313238373736352e706e67)
i got this weird result
![after](https://camo.githubusercontent.com/c07114752c45de2247270fde23caaae5ce202b3bdb8a76d912c0973dd9b34cf0/68747470733a2f2f7075752e73682f415a6431492f663835326537373535392e706e67)
with this weid structure
![after](https://camo.githubusercontent.com/8853c3d50544e6bf6df78f15c7a7a24ec44eb0fb1d1619f1f299ac3801cee1dd/68747470733a2f2f7075752e73682f415a6431692f333835666433393262342e706e67)
As you can see, the 'contact__item' is supposed inside 'contact' but instead I got it's inside 'jss20'. Its also got applied in 'home__desc'
I'm using react-reveal for animate the component and at first I think its the cause, but the result still same even when I'm remove the animation.
The fun part is, when I click the link to move to another route and back to home its become normal again. So i think the problem is with prerendered html
Already tested in latest chrome and mozilla with hard reload.
If you are curious with how i use css, and its same with another component
![code](https://camo.githubusercontent.com/cee04f3f4769add1ae60d8ef8f32cf0a4becea64fd35bd91bd80b148e553f567/68747470733a2f2f7075752e73682f415a64664e2f336366633165363939362e706e67)
The text was updated successfully, but these errors were encountered: