feat: add EXTERNAL_SCRIPTS hook for configuring MFE external scripts#290
Conversation
a5378e3 to
8433b34
Compare
8433b34 to
008be3c
Compare
|
One thing that is not clear to me in this one is whether the default GA loader is kept if we do this: and if it is, how would one remove it if they want to completely replace the external scripts. |
It's not kept. If you add any loaders here, the defaults are replaced. (The flip side is that if you still want it, you have to add it explicitly.) |
Ok, so it's not really an "add_items" (i.e. "add_items" kind of means that this only adds new scripts, not remove default ones). And if you call |
Correct. The replacement is just about the frontend-platform default, Google Analytics, which will soon be deprecated (by frontend-platform), anyway. We expect it to become a standalone Tutor plugin that takes advantage of the mechanism introduced here. |
008be3c to
f00b77a
Compare
f00b77a to
933b3a0
Compare
Co-Authored-By: Claude <noreply@anthropic.com>
933b3a0 to
e36aacc
Compare
Description
frontend-platform recently made
externalScriptsconfigurable viaenv.config.js, following the same pattern used forloggingService,analyticsService, andauthService. This allows script loaders (such asGoogleAnalyticsLoader) to be declared in configuration rather than hardcoded ininitialize().This PR adds an
EXTERNAL_SCRIPTShook to tutor-mfe so that Tutor plugins can register external scripts without resorting to patches. The hook follows the same pattern asPLUGIN_SLOTS: each item is a(mfe_name, script_config)tuple, wheremfe_nameis"all"or a specific MFE name, andscript_configis the JavaScript expression to add to theexternalScriptsconfig array.In the
env.config.jsxtemplate, external scripts are wired up outside the frontend-plugin-framework try/catch block, since they don't depend on FPF. TheexternalScriptskey is only set when scripts are actually configured, so MFE-level defaults are preserved when no scripts are registered.Depends on openedx/frontend-platform#876.
Testing
Baseline: no scripts registered. With a stock
mfeplugin, runtutor config saveand inspect the renderedenv/build/mfe/apps/<app>/env.config.jsx. Verify that noaddExternalScripts(...)calls are emitted and thatconfig.externalScriptsis never assigned, so any MFE-level defaults remain untouched.All-MFE registration. Create a throwaway Tutor plugin at
$(tutor plugins printroot)/fakeloader.pywith the following contents:Enable it with
tutor plugins enable fakeloader, then runtutor config saveand inspectenv/build/mfe/apps/<app>/env.config.jsxfor any MFE. ConfirmFakeLoaderAllis defined in the buildtime section and thataddExternalScripts(config, [FakeLoaderAll]);appears outside anyAPP_IDguard. Runtutor dev launch(or your usual dev flow), load an MFE that is running the latest version of frontend-platform (check openedx/public-engineering#505) in a browser, and confirmFakeLoaderAll ranis logged to the console on both.Per-MFE registration. Extend the same plugin file with a second loader targeted at a single MFE:
Re-run
tutor config saveand confirm the learning MFE'senv.config.jsxwraps theFakeLoaderLearningcall inif (process.env.APP_ID == 'learning'), while other MFEs do not get that call at all. Reload the learning MFE and verify bothFakeLoaderAll ranandFakeLoaderLearning ranappear in the console; reload authn and verify onlyFakeLoaderAll ranappears.Plugin disabled. Run
tutor plugins disable fakeloader && tutor config saveand confirm both the loader class definitions and theaddExternalScriptscalls disappear from the rendered templates, and thatconfig.externalScriptsis no longer assigned.LLM usage notice
Built with assistance from Claude.