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

fix: Add optional chaining to prevent history issue. #2189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danmatthews
Copy link

We've hit a strange bug where this particular line causes an issue after using Inertia::location() - it tries to read the page parameter of window.history.state which i'm assuming is reset during an Inertia::location() call?

Adding the optional chaining modifier (as already exists in another reference to this variable further up the page) would fix this for us.

We've hit a strange bug where this particular line causes an issue after using `Inertia::location()` - it tries to read the `page` parameter of `window.history.state` which i'm assuming is reset during an Inertia::location() call? 

Adding the optional chaining modifier (as already exists in another reference to this variable further up the page) would fix this for us.
@danmatthews
Copy link
Author

For context, we have an issue with the Svelte adapter, @inertiajs/svelte versions 2.0.0 and 2.0.1 that when we use an Inertia::location() call, it will trigger the following console error:

image

I can't reproduce this in a very minimal reproduction repo - seems to work fine, but likely because i'm not passing large amounts of props around like we are in our production app.

Hopefully this quick fix solves it for us without impacting any compatibility for any other adapters or the core as it's so small.

@victorfritz
Copy link

victorfritz commented Jan 17, 2025

Same error here with our production project, thank you for your fix, hop it will be merge asap 🙏

@danmatthews danmatthews changed the title Add optional chaining to prevent history issue. fix: Add optional chaining to prevent history issue. Jan 20, 2025
@joetannenbaum
Copy link
Contributor

Thanks for the PR, I'm trying to nail down a reliable reproduction of this to add as a test so I can see what's actually going on/make sure it doesn't happen again, but I'm having trouble replicating this or any of the examples from #2195.

Does anyone have a clean example of producing this error?

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

Successfully merging this pull request may close these issues.

3 participants