plone / plone.app.widgets

Integrating plone.widgets into plone
Other
7 stars 38 forks source link

Failsafe requirejs unset/reset #169

Closed petschki closed 7 years ago

petschki commented 7 years ago

Introduced in 5c75aa8d2a1637b80b461200afd5b2b51fd74f88 it might happen, that there is no define or require defined. handle this gracefully.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 74.403% when pulling 18bc1fe295e2af27e7b2f6ac16e88c1c2cf0d14d on failsafe-requirejs-unset-reset into f65ddfb49f23a5ac38b6a4efa45ead0993e6b089 on 1.x.

petschki commented 7 years ago

Hm ... one more problem of the new unset/reset scripts is, that wildcard.foldercontents resource hack isn't working anymore ... see https://github.com/collective/wildcard.foldercontents/blob/master/wildcard/foldercontents/views.py#L944 ... @thet is this unset/reset thing really needed? I never ran into those Mismatched anonymous define errors ...

thet commented 7 years ago

@petschki - i just got this error with the plone.app.event 2.x javascript, which register itself as requirejs module, if it's available. It's probably also needed for scritps like datatables. Unset/reset requirejs is done the same way in Plone 5.

I recommend to fix wildcard.foldercontents.

thet commented 7 years ago

LGTM

thet commented 7 years ago

@petschki Hm. Your code did not work for me. When require and define aren't defined before they are unset, then the mockup widgets bundle will set them they won't be set to undefined afterwards as _old_define and _old_require are undefined. But I need require and define to be undefined. I think that it's a rare case that require and define are defined before the mockup script.

I'll come back to this later. But now, it's weekend!

petschki commented 7 years ago

@thet you're right ... if they aren't define, they aren't reset. So the reset-script needs fallback:

    define = typeof(_old_define) !== 'undefined' ? _old_define : undefined;
    require = typeof(_old_require) !== 'undefined' ? _old_require : undefined;

this should do the trick ...

petschki commented 7 years ago

the wildcard.foldercontents hack should be fixed there ... I'll create an issue ...