silverstripe-admin icon indicating copy to clipboard operation
silverstripe-admin copied to clipboard

Fix registration or JS singletons across modules

Open sabina-talipova opened this issue 1 year ago • 0 comments

Description

We're assigning an instances to the ss namespace because singletons only the context on a single Browserify bundle. For example - the lib bundle exposes a singleton called router. If the framework imports router, as an external dependency, then all modules in framework will get the same copy of register when importing it. Likewise if the custom bundle imports router as an external dependency, all modules in custom will get the same copy of router. This works as expected within the context of one bundle, all modules in that bundle importing router get the exact same copy, a singleton. However this is not true across bundles. While all modules in framework get a single copy of router and all modules in custom get a single copy of router, the copy of router in framework is not the same copy of router available in custom. See SystemJS as a solution https://github.com/systemjs/systemjs

See:

  • https://github.com/silverstripe/silverstripe-admin/blob/0f18b3d40972d421f2756b6b90b55283dfc6fea2/client/src/lib/ReactRouteRegister.js#L173
  • https://github.com/silverstripe/silverstripe-admin/blob/e3d9e1debf60362cb57e2914e838234e188be5c7/client/src/lib/Router.js#L119
  • https://github.com/silverstripe/silverstripe-admin/blob/0f18b3d40972d421f2756b6b90b55283dfc6fea2/client/src/lib/TinyMCEActionRegistrar.js#L150

sabina-talipova avatar Oct 17 '23 01:10 sabina-talipova