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

Query params added with history.pushState/replaceState are removed after scrolling #2233

Open
miDeb opened this issue Feb 14, 2025 · 1 comment
Labels
react Related to the react adapter

Comments

@miDeb
Copy link

miDeb commented Feb 14, 2025

Version:

  • @inertiajs/react version: 2.0.0

Describe the problem:

On one page of my application I have to use a dependencly (@calcom/atoms) that, when making a selection in its component, "records" this by pushing a new state through the History API. This means the url in the browser is updated and something like &slot=2025-02-17T08%3A00%3A00.000Z is appended
Inertia naturally does not know about this, and after scrolling the page it itself pushes a new state to the history (to record the scroll offset), which however does not include the previous url change, causing the url to revert to a previous state. The dependency reacts badly to this in some circumstances, e.g. by immediately closing a popup it just opened.
As a workaround I removed the scroll listener Inertia adds, which fixed the issue for me. I think that's a bit of an ugly workaround, so I'm open to suggestions for a better one.

Steps to reproduce:

Call history.pushState(history.state, "" , "?query") from the console on a page with Inertia, then scroll. Observe as the query parameter in the url bar disappears.

The relevant code appears to be this:

this.current.url!,

Here the current url (as known to Inertia) is passed which will then replace the (real) current url. Since an update to the url is not the goal here, maybe it could simply not be passed so the browser doesn't update it?

@miDeb miDeb added the react Related to the react adapter label Feb 14, 2025
@neluba
Copy link

neluba commented Feb 14, 2025

This also happens with vue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react Related to the react adapter
Projects
None yet
Development

No branches or pull requests

2 participants