-
Notifications
You must be signed in to change notification settings - Fork 13
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
Flyout: not showing up on hydrated pages #278
Comments
Thanks for opening this issue. I'm transferring it to the addons repository since it fits better there.
No, it does not require re-building.
I'm experiencing the same behavior at https://mystmd-temp.readthedocs.io/latest/ It seems the page is failing with some react issues in the console. Also, I found the DOM is re-written completely in some weird way after loading the page completely, because there is a lot of things removed from it after loading. It seems that removes the addons and all the other Read the Docs features. It seems this is an issue of that particular theme and you should report it there. Keep us posted, please. |
Upstream PR where the RTD is implemented. jupyter-book/mystmd#982 Do you think it's an issue with the theme or the site generator? For debugging, we could try different themes, do you have a suggestion on which ones to try? I'm thinking of (Also to avoid confusion for other readers this is mystmd and not myst-parser + sphinx) |
I'm not sure how mystmd works and how its themes are implemented --so I don't have a suggestion here. However, its homepage has the same React issue, and its DOM is also completely rewritten in some weird way. Take a look at the JS console while loading https://mystmd.org/ |
Ok, I've opened an upstream issue. I have tried to change the theme, but it doesn't use the sphinx theme, and it is already on |
Got some feedback. We are suspecting it's related to react/hydrate: https://react.dev/reference/react-dom/client/hydrateRoot
Also relevant comment: jupyter-book/mystmd#188 (comment)
|
In jupyter-book/mystmd#997 (comment) I noted that this hydrated issue may not be 100% related to Read the Docs since it happens on their home page which is not hosted in our platform as well. |
Indeed, but it actually doesn't happen to me. In more investigation, I've seen that this is an issue with anything that injects contents in pages, and most probably in your case it's to do with browser plugins? The issue with the hydration is that it requires the content on the server to be identical with that on the client, since it takes over and re-renders all the elements under its hydrated node. But, it seems that the hydration can be limited to a sub-node, so if all the page content can be wrapped in a container node, so that the hydration is not on the |
😞 Do you know what is hydrated useful for? I'm not sure to understand its goal. Does it make sense to disable that feature?
This could be a good intermediate solution --not only of Read the Docs addons, but for any user that has plugins installed in their browser. |
Unfortunately that seems to be a staple of A related issue could be the static-site-generation, since right now it is done very naively on |
@humitos we recently switched to using Netlify for the same content, and I was surprised that their server-side additions to html served worked without issue on exactly the same content. I did a cursory look at the differences in where the modifications were made: (1) they didn't change the head or meta-tags, (2) they only added a single div at the end of the body (same with the loom chrome extension I am using, which also caused no problems); (3) they waited some amount of time (~2s) to execute the scripts and make any other client-side modifications to the dom. These resulted in no errors, and the collaboration/version bar fading in nicely. So these things should all be possible on RTD as well: My brief comparison to RTD, there were changes in the head (new meta tags and script tags for ads), the scripts executed before our hydration is run, and there are multiple places where the html is modified. |
Hey @rowanc1, this is great information! Thanks a lot for taking the time to compare them and write this down here. Everything you mention seems doable from our side, I guess. So, I will try to give it a try in the following days locally and see if I find a way to reproduce it and fixing it after adapting our code. By the way, do you know if Netlify has this process documented somewhere? Maybe that can help me understand why they wait ~2s and similar things. |
I was able to reproduce this issue locally. The manipulation that makes React to complain is this line, https://github.com/readthedocs/common/blob/bd497c8a5b383e2059de2655b0b8527c76695dd8/dockerfiles/force-readthedocs-addons.js#L18 that adds the |
(from https://react.dev/errors/418?invariant=418) So, this is definitely an issue with "Hydrating server-rendered HTML" React's feature. I suppose it makes sense to disable this feature on the doctool completely because even if we figure it out how to solve the Read the Docs' issue --there will be plenty of browser extensions that will make the docs to break. |
Meh, in fact, I was just bitten by this. I have an extension on Firefox and it was making the documentation to fail no matter what change I made. Testing on Chrome without any extension I see no hydrated issues when building on Read the Docs. |
Oh interesting, that means it affects all RTD addons. At least for flyout, I was thinking that it should still be possible on the |
I tried using 100ms timeout and 99% of the times I don't get the error. So, I understand that if the DOM is changed after React hydration validation happens everything works fine together. This is the diff I used for my tests (note that it's required to not have any browser extension too): diff --git a/src/init.js b/src/init.js
index 2a5f454..f0572ad 100644
--- a/src/init.js
+++ b/src/init.js
@@ -1,3 +1,3 @@
import * as readthedocs from "./index";
-readthedocs.setup();
+setTimeout(readthedocs.setup, 100); I think this is not an acceptable solution anyways. Adding a random timeout to all the projects to workaround this issue that only affects React projects that have hydration enabled doesn't seems to be the right direction here. I still need to understand how hydration works and why it's required to be enabled in a documentation tool like |
Today I noted that the injection of the |
About
So to confirm, even when the script is injected in the main body, as long as the RTD script is run sufficiently after the hydration it works? Does it work after the interacting with the UI elements, e.g. expanding the TOC?
Is it possible to detect when you are in a react/hydrating environment and add the timeout than? It should be a predictable |
It seems it works fine, yes.
I don't know how to detect that. I don't have experience with React 🤷🏼 |
A quick note on hydration: this is used in a lot of modern web apps and is how the server/client communicate. There are lots of docs on react hydration - this blog gives a decent overview. "Hydration expects the initial client side render to match the server side render exactly - and mutating the DOM like this during page load will always cause issues" (from remix-run/remix#9016). All interactivity in mystmd (jupyter widgets, hover, table of contents, etc.) is driven by react, and that needs to be hydrated to become interactive. Hydration issues around plugins are something that the React community knows about (e.g. facebook/react#24430). If unknown HTML is encountered (e.g. through a plugin), the app doesn't break from the user experience, it rehydrates and completely overwrites the DOM, and there is a flicker and an error message in the console. For example, this myst page on read the docs production build, does have an error and does flicker when it removes the unknown RTD html, but recovers after the initial differences in expected html are removed: For detecting the timeout, you could look at |
Yeah, we would need an event to subscribe to so we can perform our own setup after that event is triggered since the a timeout won't be reliable since it could be network connection issues or similar that take longer than the timeout we are defining. |
Could the event be created on |
It seems the latest version of React could solve this issue (facebook/react#24430 (comment)). @LecrisUT is there an easy way to build an example project using that version of React and hosting it on Read the Docs with Addons enabled? |
I would say building |
@rowanc1 am I doing something wrong with: - npm install react@rc
- npm install There's also the nuance of Edit: Ah, right I am dense, |
@LecrisUT would it be possible to test this with the latest react release? There is a user saying that similar issues were solved with that version at facebook/react#24430 (comment) |
Details
I have enabled both
Addons
andFlyout enabled
in the project dashboard, but the menu seems to not reliably show up for me. It pops up for a millisecond and then dissapears. I am not sure if it requires rebuilding when you enable/disable this feature, but I have tried it on a few other builds with similar results.Potential caveat, I am using
noscript
, but I have enabled all javascripts links and I have tested in incognito with noscript off, and the same results show up. I did not check that thoroughly when re-building the builds though.mystmd
to generate the static site.The text was updated successfully, but these errors were encountered: