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

Page is not reloaded when using router.reload with preserveUrl: true option #2162

Closed
sjongejan opened this issue Jan 3, 2025 · 5 comments
Closed

Comments

@sjongejan
Copy link
Contributor

sjongejan commented Jan 3, 2025

Versions:

  • @inertiajs/core version: 2.0.0
  • @inertiajs/vue3 version: 2.0.0

Describe the problem:

When invoking router.reload with the option { preserveUrl: true }, the page does not reload as expected, even though network requests are performed successfully. This behaviour appears to conflict with the expected outcome when using preserveUrl.

Steps to reproduce:

import { router } from '@inertiajs/vue3';

router.reload({
  preserveUrl: true,
});
  1. Implement the above code snippet in an Inertia.js project.
  2. Trigger the router.reload method.
  3. Observe that the page does not reload while network requests are being performed.

Suspected Cause:

The issue seems related to how the page is set in page.set within the core package. Specifically:

  • A promise is created during the page.set process.
  • This promise internally invokes either history.replaceState or history.pushState, depending on the circumstances.
  • These methods evaluate the preserveUrl option and terminate early without proceeding further:

The callback function (cb) associated with the promise does not appear to be invoked when preserveUrl is set to true. This might prevent the expected resolution of the reload logic.

Suggested Solution:

Verify and adjust the callback handling logic in the page.set process:

  • Ensure that the callback cb is invoked even when preserveUrl is true.
  • This would ensure consistent behaviour and allow the reload process to complete as expected.
@ravibpatel
Copy link

I am also experiencing this when using only with usePoll. It doesn't refresh the page.props even if the new values are received from the backend. Removing the preserverUrl fixes the issue but it should work with it.

@thetanaz
Copy link

thetanaz commented Jan 6, 2025

Yep I was having tremendous issues with the new WhenVisible component and I finally figured out that this was the issue, preserveUrl stops the props from refreshing (or merging in my case)

@moymat
Copy link

moymat commented Jan 6, 2025

Same issue here, preserveUrl: true seems to prevent the props from merging and the page hangs. Everything is fine when it's removed (except that the url changes, of course).

@CamKem
Copy link

CamKem commented Jan 8, 2025

#2135 will address this issue, hopefully the team is able to merge and release it soon.

@sjongejan
Copy link
Contributor Author

#2163 is merged. I will close 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

5 participants