-
-
Notifications
You must be signed in to change notification settings - Fork 556
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
[6.x] Decouple CSRF token from nocache script #11014
Open
aerni
wants to merge
14
commits into
statamic:master
Choose a base branch
from
aerni:feature/csrf-script
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The position option was only introduced in statamic#10898 to allow either Livewire or nocache to work. We can revert all this code as we’ve now got a separate CSRF route that will solve the Livewire issue.
4a73e63
to
13f1ad4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What it does
This PR takes another stab at #10306 which was reverted in #10898. The
nocache_js_position
config option introduced in the latter PR isn't optimal, as you've got to pick your poison and choose between Livewire or nocache to work as expected.This PR picks up on the idea pointed out here and extracts the CSRF token replacer script from the nocache replacer script. The CSRF replacer script is inserted as the first script in the
head
, while the nocache replacer script is placed at the end of thebody
. This way, you don't have to pick the script's position and can have both Livewire and nocache work alongside each other.Note
This PR has undergone several iterations. Previously, I put the decoupling of the scripts behind a feature flag. This wasn't optimal but allowed for a non-breaking update. With the release of Statamic 6 coming close, I figured I might as well make this a breaking change.
Breaking changes
Events
The
statamic:nocache.replaced
event is no longer dispatched when the CSRF token is replaced. It is now only dispatched by the nocache script. Instead, you should use the newstatamic:csrf.replaced
event.Script replacement
The
StaticCache::nocacheJs($script)
method now only replaces the nocache script. It doesn't touch the CSRF token script. Use the newStaticCache::csrfTokenJs($script)
method if you want to customize the CSRF script.Removed config option
The
nocache_js_position
config option introduced in #10898 is obsolete now and has been removed.Testing
Here's a basic layout that you can use for testing. Note, that the CSRF token is replaced and nocache also works. Make sure to enable the new config option and full static caching.