Don't set pjax.state unless options.push or options.replace is true #312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is part proposal but largely also a request for feedback.
Our premise is this: if the pjax call has both
push
andreplace
set to false, the call shouldn't swap out thepjax.state
. This is a degenerate use ofpjax
but it's surprising behavior from the standpoint of expecting to fall back toward basic Ajax behavior.Here's a scenario where we're getting into trouble with the current implementation. We want to change a navigation area in place (for the most part) but pushState a main content area, with interleaved calls between the two.
We have this HTML:
State 1:
State 2:
We have this pjax setup:
We have this sequence of events:
The result is that dashboard content shows in the navigation area, leaving the main area showing the previously loaded post. This happens because the pjax load of the navigation content sets
pjax.state
despite not caching the navigation content becausepush
andreplace
are false.This PR only sets
pjax.state
if eitheroptions.push
oroptions.replace
is true. We've run the existing tests and they all pass, but haven't added new tests for the above scenario.It's certainly possible that it's more appropriate to use normal Ajax for situations where you would specify both
push
andreplace
asfalse
, but it seems if these proposed changes don't introduce breakage then they would remove some surprise from a degenerate use case for Pjax.