Closed alex-ju closed 2 years ago
Although the current behaviour definitely doesn't seem 'correct', I think we'd have to treat this as a breaking change so I'm going to attach this to the 4.0 milestone.
Thank you @36degrees! I'm pretty confident I introduced this problem, so happy to work on it if the team decides so.
Had a discussion in the v4 planning session about whether we should make this change backwards compatible by supporting the current way of doing things with the new way (and then removing that in a later release). I think we're all in agreement that the current behaviour is a bug that people are now probably relying on working in that way (as we haven't had many reports of this issue). Probably needs a little bit of investigation into what the fix would look like before we know for certain whether it's something to include in v4.
Moving this into Blocked for now as I've asked Alex from GOV.UK to test this change to make sure it works for them. Waiting to hear back.
Context
When we compile the JavaScript assets to UMD we attach them to
GOVUKFrontend
, which works well when importing all components, but not so great when importing individual scripts.Problem
For example, in GOV.UK Publishing Components, when importing multiple components individually from
govuk-frontend
only the last one will be available.As a workaround, we attached the component to another global
GOVUK.Modules.[ComponentName]
right after importing it.Potential solution
Update compile-assets.js script to attach components to
GOVUKFrontend.[ComponentName]
instead ofGOVUKFrontend
.Done when
Details of breaking change
window.GOVUKFrontend.[ComponentName]
rather thanwindow.GOVUKFrontend
to avoid multiple imports for individual components overwriting each otherwindow.GOVUKFrontend
. Users must update references to account for the new naming, for example switching calls towindow.GOVUKFrontend
towindow.GOVUKFrontend.[ComponentName]