Skip to content
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

Passing ?readthedocs-diff=true breaks Links Preview #460

Closed
humitos opened this issue Dec 3, 2024 · 7 comments · Fixed by #465
Closed

Passing ?readthedocs-diff=true breaks Links Preview #460

humitos opened this issue Dec 3, 2024 · 7 comments · Fixed by #465
Assignees
Labels
Accepted Accepted issue on our roadmap Bug A bug

Comments

@humitos
Copy link
Member

humitos commented Dec 3, 2024

Steps to reproduce:

  1. Go to https://docs--11751.org.readthedocs.build/en/11751/user-defined-redirects.html?readthedocs-diff=true
  2. Hover on "custom domains" under "Root URL redirect at /" section
  3. No preview is shown, and no error is reported

If you go to https://docs--11751.org.readthedocs.build/en/11751/user-defined-redirects.html (without readthedocs-diff), links preview works properly.

@humitos humitos added Bug A bug Accepted Accepted issue on our roadmap labels Dec 3, 2024
@github-project-automation github-project-automation bot moved this to Planned in 📍Roadmap Dec 3, 2024
@agjohnson
Copy link
Contributor

Noting that passing around the URL param is not necessary either. The diff links could instead:

  • Intercept the click event
  • Save to local storge or session/etc that doc diff is enabled
  • Navigate to original link
  • Consume local storage/session/cookie etc

This would avoid passing around the url param. Maybe something to explore here instead.

@ericholscher
Copy link
Member

ericholscher commented Dec 3, 2024

This doesn't look like an issue with the GET arg, it's just docdiff in general? It's replacing the page content, so it's likely the new a elements don't have the events on them.

I don't know if we can really expect previews to work while doing a docdiff. If we want them to continue working, we probably need some way to retrigger the link selector logic after doing the replacement of the page content.

Looking at MDN, it seems we need a live nodelist, instead of a static one: https://developer.mozilla.org/en-US/docs/Web/API/NodeList#live_vs._static_nodelists

@humitos
Copy link
Member Author

humitos commented Dec 4, 2024

This doesn't look like an issue with the GET arg, it's just docdiff in general? It's replacing the page content, so it's likely the new a elements don't have the events on them.

Good point. However, the a node seems to be the one we modified already since it has the class link-preview on it and it shows the dot underlined

Screenshot_2024-12-04_14-09-59

The problem seems to be the JavaScript event attached to each of these nodes being deleted somehow.

@humitos
Copy link
Member Author

humitos commented Dec 4, 2024

Probably, a first step here would be to disable links preview when the docdiff is enabled? At least, that will remove the confusion of having these elements with dot underline where I'm expecting to trigger links preview.

I'm not sure if that will add the confusion of "Why links preview is not enabled in this project now?" 🥲

@humitos
Copy link
Member Author

humitos commented Dec 4, 2024

Looking at MDN, it seems we need a live nodelist, instead of a static one: developer.mozilla.org/en-US/docs/Web/API/NodeList#live_vs._static_nodelists

I'm not sure to follow how this would help us here 🤔

@humitos
Copy link
Member Author

humitos commented Dec 4, 2024

If we want them to continue working, we probably need some way to retrigger the link selector logic after doing the replacement of the page content.

I suppose we will want DocDiff to trigger READTHEDOCS_DOCUMENT_BODY_CHANGED or similar, so other addons can subscribe to it and update themselves. In the case of links preview, re-run the setupTooltip function.

This will be similar to what we are implementing for SPA in #157. I think these issues are related, so we may want to wait for that other issue to set the pattern here and we can use it here.

@humitos
Copy link
Member Author

humitos commented Dec 5, 2024

This would avoid passing around the url param. Maybe something to explore here instead.

I found another issue when passing the URL param: #461. I opened #462 to fix it for now and to start thinking about the idea anything external that enables/disables an add should be done via an event, so all the other addons that needs to update an internal state can do it.

@humitos humitos self-assigned this Dec 9, 2024
@humitos humitos moved this from Planned to Needs review in 📍Roadmap Dec 9, 2024
humitos added a commit that referenced this issue Dec 10, 2024
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
@github-project-automation github-project-automation bot moved this from Needs review to Done in 📍Roadmap Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Bug A bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants