Skip to content

Conversation

@zanderle
Copy link
Collaborator

Closes #157

@zanderle zanderle requested review from a team and humitos as code owners November 29, 2024 13:46
@zanderle zanderle requested a review from agjohnson November 29, 2024 13:46
@zanderle zanderle force-pushed the zanderle/157-listen-on-pushState-and-replaceState-changes branch from 68a5305 to 2f3f8f0 Compare November 29, 2024 13:47
@zanderle
Copy link
Collaborator Author

@humitos this just does the monkey-patching for now (haven't added any listeners yet). Do we want to do a test-build with this, to see if it correctly picks up the "page changes", before we move on to the next step?

@zanderle zanderle force-pushed the zanderle/157-listen-on-pushState-and-replaceState-changes branch from 2f3f8f0 to 7aee62e Compare November 29, 2024 13:50
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a small review and left a few questions.

@humitos
Copy link
Member

humitos commented Dec 2, 2024

Do we want to do a test-build with this, to see if it correctly picks up the "page changes", before we move on to the next step?

How hard would it be to create a simple example for this using the index.html page from this repository?

I tested using test-builds locally and I can confirm the custom method is called when changing pages on Docusaurus and Material for MkDocs (I added some small console.log) --but I don't want you to deal with my current setup since it's a complex.

@zanderle
Copy link
Collaborator Author

zanderle commented Dec 2, 2024

Do we want to do a test-build with this, to see if it correctly picks up the "page changes", before we move on to the next step?

How hard would it be to create a simple example for this using the index.html page from this repository?

I tested using test-builds locally and I can confirm the custom method is called when changing pages on Docusaurus and Material for MkDocs (I added some small console.log) --but I don't want you to deal with my current setup since it's a complex.

I think I can make it work locally, to develop, and then I'll ask you to do a proper test on your setup

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here seem fine, no additions to the notes here 👍

@zanderle
Copy link
Collaborator Author

Do we want to do a test-build with this, to see if it correctly picks up the "page changes", before we move on to the next step?

How hard would it be to create a simple example for this using the index.html page from this repository?

I tested using test-builds locally and I can confirm the custom method is called when changing pages on Docusaurus and Material for MkDocs (I added some small console.log) --but I don't want you to deal with my current setup since it's a complex.

I added this to the PR, but we can remove it, if you think it's redundant

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

This is the first step required for the underlying work. Here, we are detecting that the URL has changed and triggering a custom event, which is 💯

The next step here is to subscribe and use this event to reload all the addons that require reloading. My idea is to investigate the usage of Lit context and make the config object to become an object shared by that context.

With that, we can subscribe to this event, re-fetch the updated data from the endpoint and update the config object so the addons refresh automatically.

I wasn't able to jump into exploring this idea yet, but I should probably do it soon.

history.pushState({}, "", `#url-${randomHash}`);
});

window.addEventListener("readthedocsUrlChanged", (ev) => {console.log("URL Change detected!", ev)});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@humitos
Copy link
Member

humitos commented Jan 22, 2025

I pushed a few changes. I'm going to merge this work now so I can continue working on #491 and #504.

@humitos humitos merged commit 4599e33 into main Jan 22, 2025
4 checks passed
@humitos humitos deleted the zanderle/157-listen-on-pushState-and-replaceState-changes branch January 22, 2025 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Single Page Applications (SPA) for addons that depend on the URL

4 participants