-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support Single Page Applications (SPA) for addons that depend on the URL #157
Comments
Besides DocDiff, now that we support "keeping on the same page when changing version/language" in the Flyout, this addon also suffers this problem. This happens on Docusaurus and Markdoc too. |
I realized that Links Preview also suffer from this. We will need to re-trigger the setup once the URL changes. Otherwise, previews are not installed on the new links of the page. Steps to reproduce:
|
I think it would be good to implement this as an utils function that triggers an event |
@humitos so if I understand correctly, you want to use Navigation API? The support for this isn't looking to good yet :/ https://developer.mozilla.org/en-US/docs/Web/API/Navigation/navigate_event An alternative (which I'm not a fan of) would be to monkey-patch Another possibility (not sure how feasible this would be) could be to add a OR could we make this a responsibility of the theme instead? If your theme is using SPA, you need to fire |
Hrm, OK. That sounds like a no go, then. Support is pretty limited 😞
I'm not a fan either, but I think we can probably start here for now to have an initial implementation and see how it behaves. By the way, is it possible the change the URL skipping the
I'm not sure to understand how this would work. Can you expand on this idea?
Do you mean Docusaurus and/or Material for MkDocs triggering this event? If so, I don't think these frameworks will ever implement such integration, so I would try to not rely on them if possible. |
Yeah, it doesn't seem viable at this point.
Yeah, we can try that 👍
You mean, somehow change the URL without using
I looked through the source code of how mkdocs do instant-loading, and it seems that any script that's on the page will be executed when the page is loaded. So if we could have a script on each of their pages, that would be executed, that could be a way to trigger the event? And to be clear: just thinking out loud here, no idea if this would work.
Ah, too bad. |
Hrm, interesting. If it works like you are describing, it should work for us without doing anything specific on the Material for MkDocs case, since we are including a I created an example for Material for MkDocs with "Instant loading" enabled at https://test-builds.readthedocs.io/en/material-mkdocs-instant-loading/. It seems it doesn't re-run our addons code when switching pages 🤔 ... maybe, it is re-running our code, but since the Lines 376 to 389 in c389f31
|
Hm, yeah it probably doesn't work the way I would want it to. I looked at this section, but I'm not sure it does the trick: Maybe it would work if the However upon further research, I found this: The problem here is that I assume you want a general solution. Not a solution that would work just for mkdocs |
Yes, we want a general solution that works independently from the documentation tool and/or theme. |
@humitos monkey-patching until we find something better then? |
Yes. I think it's fine for now. |
We talked about Lit context pattern, https://lit.dev/docs/data/context/. I think we may be able to put the This is just an idea to explore... 😄 |
The pattern using Lit context should be useful to for #356 as well, because we will be able to initialize addons when new responses arrives from the server. Only those addons with all the required data will be enabled and they will be updated with new data as it arrives 💯 |
Re context API, this is maybe where https://lit.dev/docs/data/context/#contextroot However, the docs here aren't clear and there aren't great examples for ContextRoot 🤷 |
A new event `READTHEDOCS_ROOT_DOM_CHANGED` is triggered when the "Visual diff" is enabled/disabled after the DOM was modified. This allows other addons to subscribe to this event to re-initialize if required. I used this event from links preview to call `setupTooltips` again to re-install tooltips on these links. I migrated links preview to a `LitElement` to be able to make usage of this pattern and follow what we already had. We will be able to do something similar on #157
A new event `READTHEDOCS_ROOT_DOM_CHANGED` is triggered when the "Visual diff" is enabled/disabled after the DOM was modified. This allows other addons to subscribe to this event to re-initialize if required. I used this event from links preview to call `setupTooltips` again to re-install tooltips on these links. I migrated links preview to a `LitElement` to be able to make usage of this pattern and follow what we already had. We will be able to do something similar on #157 Closes #460
Material for MkDocs and other doctools (I think that Docusaurus too) implement a feature that load the content of the page without making a regular request to the server 1:
This makes addons that depend on the actual URL to not work as expected (e.g. docdiff). When loading the page, the addons API is hit with
url=
but then the user clicks on an internal link, which uses the instant reload feature to load the page content but our addons doesn't do another request with theurl=
field updated, making docdiff to use the old URL to compare against.I think we could listen to an event to check if the URL has changed and if so, make a request to the addons API again with the updated
url=
attribute. It seems there is a navigator API to do this, but it's experimental for now, tho: https://developer.mozilla.org/en-US/docs/Web/API/Navigation_APIFootnotes
https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/#instant-loading ↩
The text was updated successfully, but these errors were encountered: