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

History: pushState() method section-content is confusing #30014

Closed
zjlovezj opened this issue Nov 3, 2023 · 1 comment · Fixed by #30169
Closed

History: pushState() method section-content is confusing #30014

zjlovezj opened this issue Nov 3, 2023 · 1 comment · Fixed by #30169
Labels
Content:Glossary Glossary entries Content:WebAPI Web API docs effort: small This task is a small effort. goal: accuracy (Experimental label) Issues about inaccurate/incorrect content. goal: clarity (Experimental label) Issues about unclear/confusing/inconcise content.

Comments

@zjlovezj
Copy link
Contributor

zjlovezj commented Nov 3, 2023

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

What specific section or headline is this issue about?

section-content

What information was incorrect, unhelpful, or incomplete?

This method is asynchronous. Add a listener for the popstate event in order to determine when the navigation has completed. The state parameter will be available in it.

What did you expect to see?

This method is asynchronous. sort of implies that the popstate event listener got a event when history.push has resolved.

And how do the user know when history.push has resolved? Or maybe it doesn't matter.

popstate event may never fired as popstate described.

I think it should made clear that history.push trigger no events, correct me if I'm wrong.

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

From blank page to abc.html, abc.html includes below js

history.pushState({a: 1}, '');
history.pushState({a: 2}, '');

If pushState without change url, at least in Chrome,

  1. click browser Back button will go back to the blank page
  2. do history.back() will stay at the abc.html and trigger a popstate event

Maybe this behavior worth a notice.

MDN metadata

Page report details
@zjlovezj zjlovezj added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Nov 3, 2023
@github-actions github-actions bot added Content:Glossary Glossary entries Content:WebAPI Web API docs labels Nov 3, 2023
@wbamberg
Copy link
Collaborator

wbamberg commented Nov 3, 2023

I'm not very familiar with this API and our docs on it (especially the guide) are very confusing, but yes, this looks like a mistake to me. pushState() doesn't cause a navigation, it just adds an entry to the history. So "when the navigation has completed" is not connected to pushState() completing, right?

This paragraph was added in #25702, to match some APIs like forward() that do cause a navigation. I wonder if this was an error - @teoli2003 do you know?

@caugner caugner added effort: small This task is a small effort. goal: clarity (Experimental label) Issues about unclear/confusing/inconcise content. goal: accuracy (Experimental label) Issues about inaccurate/incorrect content. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Glossary Glossary entries Content:WebAPI Web API docs effort: small This task is a small effort. goal: accuracy (Experimental label) Issues about inaccurate/incorrect content. goal: clarity (Experimental label) Issues about unclear/confusing/inconcise content.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants