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

History back shouldn't trigger full rerender if Inertia's state didn't change #1821

Closed
artygrand opened this issue Mar 8, 2024 · 4 comments
Labels
react Related to the react adapter

Comments

@artygrand
Copy link

Version:

  • @inertiajs/react version: 1.0.15

Describe the problem:

Currently I rewrite my modal manager from react-router, where everything works fine. I use history to change private state, and Inertia rerenders whole page, even I didn't change its state

Steps to reproduce:

When I open modal I call history.pushState({...history.state, modal: modal.id}, ''); hence I keep all Inertia data.
Later, when I click browser back button or call history.go(-1) I close modal on POP event.

But with this action, current page fully rerenders all components and of cource triggers useEffect(() => {}, [])
Thankfully, it's coming at least without calling to backend.

Thank you!

@artygrand artygrand added the react Related to the react adapter label Mar 8, 2024
@shengslogar
Copy link

Inertia has history-based state management built in. You'll probably have better luck using that system instead of building your own.

https://inertiajs.com/remembering-state#manually-saving-state

@artygrand
Copy link
Author

@shengslogar, problem not with data storing, but with returning back without side effect.
router.remember(data, 'my-key') is replaces state, not pushes new, as I just tested. I can't return back to same page with it

@reinink
Copy link
Member

reinink commented May 28, 2024

Hey! Manually using history.pushState is not currently supported with Inertia.js.

That said I hope to eventually add the ability to make client-side only visits using an API like Inertia.push().

My recommendation right now would be to use Inertia props to open/close a dialog like this. Yes that means hitting the server, but, at least at this time, that's the "Inertia way" 👍

@reinink reinink closed this as completed May 28, 2024
@artygrand
Copy link
Author

Thanks for giving us hope for client-side visits. This feature will fix more problems, such as compatibility with use-query-params

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

3 participants