mirror of
https://github.com/symfony/stimulus-bundle.git
synced 2026-03-24 01:12:07 +01:00
bug #2590 [StimulusBundle] Fix lazy load Stimulus controllers with Turbo (smnandre)
This PR was merged into the 2.x branch. Discussion ---------- [StimulusBundle] Fix lazy load Stimulus controllers with Turbo | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #2576 / maybe #2583 | License | MIT Partial revert of some changes to fix issues with Turbo and lazyload Stimulus controllers Commits ------- 111fd4cda85 fix: lazy load Stimulus controllers with Turbo
This commit is contained in:
21
assets/dist/loader.js
vendored
21
assets/dist/loader.js
vendored
@@ -53,22 +53,17 @@ class StimulusLazyControllerHandler {
|
||||
return;
|
||||
}
|
||||
new MutationObserver((mutationsList) => {
|
||||
for (const mutation of mutationsList) {
|
||||
switch (mutation.type) {
|
||||
case 'childList': {
|
||||
for (const node of mutation.addedNodes) {
|
||||
if (node instanceof Element) {
|
||||
extractControllerNamesFrom(node).forEach((controllerName) => {
|
||||
this.loadLazyController(controllerName);
|
||||
});
|
||||
}
|
||||
for (const { attributeName, target, type } of mutationsList) {
|
||||
switch (type) {
|
||||
case 'attributes': {
|
||||
if (attributeName === controllerAttribute &&
|
||||
target.getAttribute(controllerAttribute)) {
|
||||
extractControllerNamesFrom(target).forEach((controllerName) => this.loadLazyController(controllerName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'attributes': {
|
||||
if (mutation.attributeName === controllerAttribute) {
|
||||
extractControllerNamesFrom(mutation.target).forEach((controllerName) => this.loadLazyController(controllerName));
|
||||
}
|
||||
case 'childList': {
|
||||
this.lazyLoadExistingControllers(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,26 +99,23 @@ class StimulusLazyControllerHandler {
|
||||
return;
|
||||
}
|
||||
new MutationObserver((mutationsList) => {
|
||||
for (const mutation of mutationsList) {
|
||||
switch (mutation.type) {
|
||||
case 'childList': {
|
||||
// @ts-ignore
|
||||
for (const node of mutation.addedNodes) {
|
||||
if (node instanceof Element) {
|
||||
extractControllerNamesFrom(node).forEach((controllerName) => {
|
||||
this.loadLazyController(controllerName);
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (const { attributeName, target, type } of mutationsList) {
|
||||
switch (type) {
|
||||
case 'attributes': {
|
||||
if (mutation.attributeName === controllerAttribute) {
|
||||
extractControllerNamesFrom(mutation.target as Element).forEach((controllerName) =>
|
||||
if (
|
||||
attributeName === controllerAttribute &&
|
||||
(target as Element).getAttribute(controllerAttribute)
|
||||
) {
|
||||
extractControllerNamesFrom(target as Element).forEach((controllerName) =>
|
||||
this.loadLazyController(controllerName)
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'childList': {
|
||||
this.lazyLoadExistingControllers(target as Element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user