Resources registry: stub js modules not working as expected?

Hi,as i understand from the documentation, stub modules is a conf used to avoid duplicated pattern imports.

I'm trying a product (collective.venue) that has several dependencies and in particular plone.patternslib.

Patternslib register two bundles with some stub modules (select2 for example) in registry.xml

Installing that product (patternslib) in a clean Plone 5.1 site (built with coredev buildout), when i open the edit form for News Items (for example), i have several errors in the browser console like this :

patterns.pat.select2: Failed while initializing 'select2' pattern. query function not defined for Select2 s2id_autogen9

And installing collective.venue, i have these errors doubled, because it (or another its dependency) registers a new bundle with select2 as stub resource too.

If i understand correctly, the problem is that there are several js loaded in the page, that tries to instantiate/use the same pattern..and this should be avoided by stub modules.

Anyone else noticed similar problems with stub modules?

@agitator had these problems too. AFAI can remember we got around this by chaning bundle registrations. We had several js script files as bundles installed directly and then registered them as legacy scripts.

@agitator - do you remember how we dealt with this problem?

Some more remarks:

  • Maybe it's something in the Select 2 libraries initialization code?
  • The related items pattern could be a candidate to look at too.
  • For collective.venue you only need the bundle-leaflet and not the patterns bundle.
  • For my Plone 5 based projects I customize the plone and plone-logged-in bundles to include all patterns I need and try to avoid registering other bundles.

Thanks for your reply.

For sure i can try to fix wrong bundles installation on my product (i use a wrapper over c.venue).

And about your last sentence: how do you manage it? Manually or with a script? How do you handle products that install new bundles like c.venue for example? Do you remove them manually and then add needed resources to the plone bundles?
This looks good for minimizing loaded resources, but a nightmare for maintainability..or am i missing something? was the problematic part in our case.

1 Like

Ok, with @agitator fix i don't have errors anymore.
The problem was that registry were initialized twice? And maybe select2 doesn't handle this in the right way?

Are there some side-effects in removing registry.init() in bundle-leaflet or in any bundle in general? Some sorting priority? Registry should be initialized anyway.

Probably @agitators answer fixes your troubles. That means removing all the mentioned initialization code from addons which include them.
Regarding my customized plone and plone-logged-in bundles: I use the plone-compile-resources script to build bundles. Plus I like to have total control over the resources, so for any plugin which register bundles I remove it in my registry.xml and add the necessary resouces to my custom plone.js bundle script. I think maintainability is still OK that way.


About your solution: it depends on use-cases, but it has sense :wink: