Skip to content

feat: add EXTERNAL_SCRIPTS hook for configuring MFE external scripts#290

Open
arbrandes wants to merge 1 commit intooverhangio:mainfrom
arbrandes:external-scripts
Open

feat: add EXTERNAL_SCRIPTS hook for configuring MFE external scripts#290
arbrandes wants to merge 1 commit intooverhangio:mainfrom
arbrandes:external-scripts

Conversation

@arbrandes
Copy link
Copy Markdown
Collaborator

Description

frontend-platform recently made externalScripts configurable via env.config.js, following the same pattern used for loggingService, analyticsService, and authService. This allows script loaders (such as GoogleAnalyticsLoader) to be declared in configuration rather than hardcoded in initialize().

This PR adds an EXTERNAL_SCRIPTS hook to tutor-mfe so that Tutor plugins can register external scripts without resorting to patches. The hook follows the same pattern as PLUGIN_SLOTS: each item is a (mfe_name, script_config) tuple, where mfe_name is "all" or a specific MFE name, and script_config is the JavaScript expression to add to the externalScripts config array.

In the env.config.jsx template, external scripts are wired up outside the frontend-plugin-framework try/catch block, since they don't depend on FPF. The externalScripts key 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.

LLM usage notice

Built with assistance from Claude.

Co-Authored-By: Claude <noreply@anthropic.com>
@mboisson
Copy link
Copy Markdown

mboisson commented Apr 17, 2026

One thing that is not clear to me in this one is whether the default GA loader is kept if we do this:

    EXTERNAL_SCRIPTS.add_items([
        (
            "all",
            "CookieYesLoader",
        ),
    ])

and if it is, how would one remove it if they want to completely replace the external scripts.

@arbrandes
Copy link
Copy Markdown
Collaborator Author

arbrandes commented Apr 17, 2026

@mboisson

whether the default GA loader is kept

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.)

@mboisson
Copy link
Copy Markdown

mboisson commented Apr 17, 2026

@mboisson

whether the default GA loader is kept

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 add_items multiple times, it adds each script without overwriting the previous ones ?

@arbrandes
Copy link
Copy Markdown
Collaborator Author

arbrandes commented Apr 18, 2026

if you call add_items multiple times, it adds each script without overwriting the previous ones ?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending Triage

Development

Successfully merging this pull request may close these issues.

3 participants