Skip to content

router.replaceWith calls pushState on the history object with refreshModel QP #18416

Open
@mehulkar

Description

@mehulkar

https://github.com/mehulkar/ember-example-replace-push-state

I think this may have the same root cause as #15801, but it manifests differently.

Problem

If a queryParam is configured to refreshModel: true, calls to router.replaceWith end up calling pushState on history instead of replaceState.

I'm not totally sure how this would manifest as a "bug" in a browser for an end user, but in my case, I have a custom Location using a custom history object, and calling pushState when we really meant to replace causes it to get an extra entry history entry.

Debugging

It seems that Ember (or underlying router.js lib thinks that because of the queryParams refreshModel config, this replaceWith transition is invalid, and it cancels it and generates its own.

Because router.replaceWith is implemented like this:

replaceWith() {
  this.transitionTo(...arguments).method('replace');
}

the transitionTo() promise gets replaced, and all the async stuff that causes the URL to update happens on the new promise, which does not yet have the urlMethod set to replace.

One possible solution here is that instead of using transitionTo(), a Transition object should be constructed with urlMethod set as part of the constructor, so that it does the right thing throughout its lifecycle, but that seems like a really big change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions