Skip to content

Commit 4750a50

Browse files
committed
Updated stimulus recipe
1 parent 52a9975 commit 4750a50

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

assets/controllers/csrf_protection_controller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const nameCheck = /^[-_a-zA-Z0-9]{4,22}$/;
22
const tokenCheck = /^[-_/+a-zA-Z0-9]{24,}$/;
33

44
// Generate and double-submit a CSRF token in a form field and a cookie, as defined by Symfony's SameOriginCsrfTokenManager
5+
// Use `form.requestSubmit()` to ensure that the submit event is triggered. Using `form.submit()` will not trigger the event
6+
// and thus this event-listener will not be executed.
57
document.addEventListener('submit', function (event) {
68
generateCsrfToken(event.target);
79
}, true);
@@ -33,8 +35,8 @@ export function generateCsrfToken (formElement) {
3335
if (!csrfCookie && nameCheck.test(csrfToken)) {
3436
csrfField.setAttribute('data-csrf-protection-cookie-value', csrfCookie = csrfToken);
3537
csrfField.defaultValue = csrfToken = btoa(String.fromCharCode.apply(null, (window.crypto || window.msCrypto).getRandomValues(new Uint8Array(18))));
36-
csrfField.dispatchEvent(new Event('change', { bubbles: true }));
3738
}
39+
csrfField.dispatchEvent(new Event('change', { bubbles: true }));
3840

3941
if (csrfCookie && tokenCheck.test(csrfToken)) {
4042
const cookie = csrfCookie + '_' + csrfToken + '=' + csrfCookie + '; path=/; samesite=strict';

assets/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import '../css/app/treeview.css';
2828
import '../css/app/images.css';
2929

3030
// start the Stimulus application
31-
import '../bootstrap';
31+
import '../stimulus_bootstrap';
3232

3333
// Need jQuery? Install it with "yarn add jquery", then uncomment to require it.
3434
const $ = require('jquery');

symfony.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,18 +655,18 @@
655655
"version": "v1.1.5"
656656
},
657657
"symfony/stimulus-bundle": {
658-
"version": "2.27",
658+
"version": "2.31",
659659
"recipe": {
660660
"repo": "github.com/symfony/recipes",
661661
"branch": "main",
662-
"version": "2.20",
663-
"ref": "e058471c5502e549c1404ebdd510099107bb5549"
662+
"version": "2.24",
663+
"ref": "3357f2fa6627b93658d8e13baa416b2a94a50c5f"
664664
},
665665
"files": [
666-
"assets/bootstrap.js",
667666
"assets/controllers.json",
668667
"assets/controllers/csrf_protection_controller.js",
669-
"assets/controllers/hello_controller.js"
668+
"assets/controllers/hello_controller.js",
669+
"assets/stimulus_bootstrap.js"
670670
]
671671
},
672672
"symfony/stopwatch": {

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Encore
7171
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
7272
.splitEntryChunks()
7373

74-
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
74+
// enables the Symfony UX Stimulus bridge (used in assets/stimulus_bootstrap.js)
7575
.enableStimulusBridge('./assets/controllers.json')
7676

7777
// will require an extra script tag for runtime.js

0 commit comments

Comments
 (0)