Skip to content

Commit

Permalink
fix(relateditems): Move Select2 out of init.
Browse files Browse the repository at this point in the history
If it wasn't already registered, it would register and scan the document now.
If there were previous relateditems already modifying the DOM structure and placing pat-select2 classes to some items, the import here would try to initialize them.
But those pat-select2 items were meant to be initialized via the Patternslib API and not automatically and are missing some configuration needed by select2 (query attribute...).
By moving the Select2 out of the init and importing it early fixes this problem.

Note: This happened in plone.app.mosaic with module federation.
pat-select2 was already directly imported by the main Mockup bundle.
But since we didn't have a global pattern registry, the pattern was re-initialized where it wouldn't have to.
Since the change in Patternslib 8.0.0 with a global pattern registry this fix might become obsolete.

However, we should have an eye on dynamic pattern imports immediately registering and scanning the docment and possibly prevent that in some way.
See: Patternslib/Patterns#961
  • Loading branch information
thet committed Mar 30, 2022
1 parent d791b8e commit 69a17a9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/pat/relateditems/relateditems.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Base from "@patternslib/patternslib/src/core/base";
import _t from "../../core/i18n-wrapper";
import utils from "../../core/utils";
import registry from "@patternslib/patternslib/src/core/registry";
import Select2 from "../select2/select2";

const KEY = {
LEFT: 37,
Expand Down Expand Up @@ -503,7 +504,6 @@ export default Base.extend({
},

init: async function () {
const Select2 = (await import("../select2/select2")).default;
(await import("bootstrap")).Dropdown;
import("./relateditems.scss");

Expand Down

0 comments on commit 69a17a9

Please sign in to comment.