Skip to content

Remove jQuery throttle-debounce dependency#6811

Open
hlfan wants to merge 1 commit intoopenstreetmap:masterfrom
hlfan:id-no-throttle
Open

Remove jQuery throttle-debounce dependency#6811
hlfan wants to merge 1 commit intoopenstreetmap:masterfrom
hlfan:id-no-throttle

Conversation

@hlfan
Copy link
Collaborator

@hlfan hlfan commented Feb 13, 2026

iD already throttles its hash updates. Hooking into this allows dropping the vendored dependency, leaving only leaflet-related ones.


let hashChangedAutomatically = false;
id.map().on("move.embed", parent.$.throttle(250, function () {
window.history.replaceState = function () {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You do not want to overwrite basic Browser APIs.
https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've now made it fire a custom event. Is that override acceptable?

@HolgerJeromin
Copy link
Collaborator

Can we have instead a (throttled) event from iD on its parent like?

window.parent?.postMessage('id-hash-update', '*' /* This is no sensitive data, so ok to allow all targets */);

@HolgerJeromin
Copy link
Collaborator

Now we have postmessage and hooking into replaceState.
I wanted to suggest replacing replaceState hook with the postmessage.
Yeah, that needs adjustment in iD (and not the id-embedder) probably.

@hlfan hlfan marked this pull request as ready for review February 17, 2026 15:38
@tomhughes
Copy link
Member

Does the second change actually make anything simpler? It certainly increases the amount of code...

@hlfan
Copy link
Collaborator Author

hlfan commented Feb 17, 2026

Does the second change actually make anything simpler?

It decreases the coupling between the parent and the iframe.
With it, the parent is fully in control of its listeners and doesn't have that amount of cross-context calls. Each side now owns its own responsibilities and sends events to the counterpart if it needs something.

@HolgerJeromin
Copy link
Collaborator

My favorite solution would be here in this repo in one file window.addEventListener("message", ... and in the id repo window.parent?.postMessage('id-hash-update', '*');

@hlfan
Copy link
Collaborator Author

hlfan commented Feb 18, 2026

Yeah that would be nice, or exposing iD's lodash utilities similarly to d3.

@tyrasd which option do you think would be more in-scope for the iD repo?

@hlfan
Copy link
Collaborator Author

hlfan commented Mar 2, 2026

Does the second change actually make anything simpler? It certainly increases the amount of code...

I've dropped this change for now.

window.dispatchEvent(new CustomEvent("replaceHistoryState", { detail: args }));
return result;
};
})();
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me very uneasy. Is this overwrite common? Did @HolgerJeromin have an opinion on this? I saw the comment was resolved.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not like this approach as you know, but it is not unusual in JS world.

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.

4 participants