inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.58k stars 437 forks source link

preservScroll in scroll-region not working #2114

Open filecc opened 1 day ago

filecc commented 1 day ago

Version:

Describe the problem:

I have a div with a scrollable list: every element in that list is a button. Clicking the button trigger a get request to the server and the serve (for simplicity) redirect back to the view. I want the scroll position in the div to be preserved after the redirect back, but instead it's always reset to the top of the page.

Steps to reproduce:

method

const submit = async () => {
 router.get('/account/notification/' + notification.id , { preserveScroll: false }) 
}

component

<main className="h-dvh overflow-y-hidden">
    <div scroll-region={"true"} className="overflow-y-auto">     
        <button  onClick={submit}>Notification</button>
       {/* ...a very looong list*/}
     </div>
</main>

route

public function notification_mark($id)
    {
      /* various operations */

        return to_route('account.notifications');
    }

Doesn't matter what I put in the preserveScroll parameter, every time scroll position get restored to the top of the page, while I would love the it stays where I clicked first. I already tried with the form helper, with the Link component, nothing works. Also, doing as per the documentation

<div class="overflow-y-auto" scroll-region>
  <!-- Your page content -->
</div>

produce a warning:

Warning: Received `true` for a non-boolean attribute `scroll-region`.

Removing the "overflow-y-auto" and letting the page go for itself do the tricks.. but it's not what I want and what is menta to be.

Any help would be VERY appreciated.

Thanks!

mgriego commented 1 day ago

I've been running into similar issues and discovered that the previous issues on this were closed, but a new version hasn't yet been released. The fixes for this are in the 1.3.0 beta versions (you can see the release notes that include these fixes here: https://github.com/inertiajs/inertia/releases/tag/v1.3.0-beta.1). A final 1.3.0 release is needed for these fixes to be present in the npm package.