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

[v2.0.0] Setting preserveUrl to true prevents next page items merging #2140

Open
jamiewatsonuk opened this issue Dec 17, 2024 · 3 comments
Open

Comments

@jamiewatsonuk
Copy link

jamiewatsonuk commented Dec 17, 2024

Versions:

  • @inertiajs/core version: 2.0.0

Describe the problem:

When setting preserveUrl for the WhenVisible component, data loaded from the next page is not merged. In fact nothing happens. Not setting preserveUrl at all allows infinite scroll to work (ie. the next items are merged) but of course the page url is changed per each request.

This was introduced between v2.0.0-beta.2 and v2.0.0-beta.3.

Specifically, a refactor to the pushState and replaceState methods of history.ts in the core:

history.ts change

The callbacks are required to fulfill the promise in page.ts.

My rudimentary fix was something along the lines of the following (in replaceState / pushState) but I have am not sure of the wider impact of that kind of change.

if (isServer) {
    return
}

if (this.preserveUrl) {
    cb && cb()
    return
}

I mention the diff between beta2 and beta3 but the problem exists on v2.0.0 just the same.

Steps to reproduce:

This is easily reproduced in the Vue3 playground environment.

Check out this project on the latest tag and follow the steps to get the project running. From the vue3 playground visit the infinite scroll route and see that the next page does not get merged when you reach the end of the list.

(Note: The playground is also sort of broken for vue3 - you will need to replace :once="false" with always in the <WhenVisible> component of the InfiniteScroll.vue page. )

@PedroAugustoRamalhoDuarte

I dont think is a bug only with WhenVisible component but all partials reload with data params and preserveUrl. I have try this and does not work with inertia v2.0.0

  useEffect(() => {
    // Does not changes tasks and pagy props
    setTimeout(() => {
      router.reload({
        only: ["tasks", "pagy"],
        preserveUrl: true,
        data: {page: 2}
      });
    })
  }, []);

@PedroAugustoRamalhoDuarte

@jamiewatsonuk I think your proposed fix makes sense.

@PedroAugustoRamalhoDuarte

Maybe this PR #2135 is a fixes for this issue

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

No branches or pull requests

2 participants