Repository navigation
Conversation
|
Thanks for the pull request, @rpenido! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
b5f4e97 to
ec088e7
Compare
ec088e7 to
25702c6
Compare
| * `defaults` map naming the active light and dark variants, while tutor-indigo | ||
| * (https://github.com/overhangio/tutor-indigo) ships only a `variants` map with | ||
| * nothing pointing at one. So read `defaults` when it is there, and otherwise |
There was a problem hiding this comment.
@rpenido Note that the Theme interface type in frontend-base is very lenient: the defaults map isn't a required key, in fact no keys are required. So the tutor-indigo one may not be a special case.
There was a problem hiding this comment.
You are right. For now, nit update to the docs here: 949f631
| # Opt-in styling for this block. When enabled the block renders its HTML in | ||
| # a shadow root carrying the MFE theme, so page styles cannot reach the | ||
| # content and the content cannot leak styles back into the page. | ||
| include_theme = Boolean( |
There was a problem hiding this comment.
@rpenido I'm wondering if something like "use_mfe_theming" or an inverse "use_legacy_theming" might be more appropriate. The more I think about it, the more "include_theme" seems a little vague.
There was a problem hiding this comment.
"use_mfe_theme" would match the display name, and I think be more informative. :)
| frag.add_javascript(resource_loader.load_unicode("static/js/html_block.js")) | ||
|
|
||
| # The MFE config API is only served by the LMS, so point at it | ||
| # explicitly; in Studio this falls back to the CDN defaults. | ||
| frag.initialize_js( | ||
| "HtmlBlock", | ||
| { | ||
| "include_theme": self.include_theme, | ||
| "mfe_config_api": f"{settings.LMS_ROOT_URL}/api/mfe_config/v1", | ||
| }, | ||
| ) |
There was a problem hiding this comment.
@rpenido I feel like for best backwards compatibility, it would be good to initialise the non-include-theme variant exactly as before, including the barebones HtmlBlock js implementation. Although I'm not sure about namespacing here - would the HtmlBlock js function conflict with that of other Text blocks on the same page?
There was a problem hiding this comment.
I am not sure if I agree with you on this one. Since we added more functionality to the init function (using html_block.js instead of just using an empty function like before), I think we should load it for every case and make it handle the parameters there, abstracting its logic from html.py.
In the future if someone needs other JS features for our HTML block, he doesn't need to add a new condition for loading the html_block.js or, in the worst case, be tempted to add a new html_block_for_my_feature.js file.
Does that make sense?
And the new HTMLBlock declared function early returns if we don't have initArgs of the included_theme. I don't think we are at risk to add a regression here.
if (!initArgs || !initArgs.include_theme) {
return;
}
There was a problem hiding this comment.
@rpenido yep that makes sense, thanks for checking :) I think I'm just aware that this html block is also used for the "raw html" block, which is used for arbitrary interactive (js) features - eg. the demo course feedback buttons:
| */ | ||
| function getThemes(mfeConfigApiUrl) { | ||
| return fetch(mfeConfigApiUrl) | ||
| .then(function (response) { return response.json(); }) |
There was a problem hiding this comment.
@rpenido is it possible to use modern async/await syntax in this file? Or are we keeping it like this for compatibility with older browsers?
5583c49 to
e69c160
Compare
e69c160 to
d4ed131
Compare
d4ed131 to
394b71d
Compare
Description
Adds an opt-in
include_themesetting to the Text (HTML) XBlock. When it is on, the block renders its author-supplied HTML inside a shadow root and applies the deployment's Paragon theme to it, so page styles cannot reach the content and the content cannot leak styles back out into the page.Blocks created before this change, and blocks where the author leaves the setting off, render exactly as they did: the legacy
html.cssis loaded for them and skipped only for themed blocks.Testing instructions
Setup
To check the feature, the deployment has to publish Paragon theme URLs the block can read, including one that cannot be missed. A single Tutor plugin does all of it and carries its own check stylesheet, so there is nothing else to create or mount. It also adds the Studio origin to the LMS CORS whitelist: Studio renders the block in an iframe on its own origin, from where the config API is not reachable unless that origin is allowed. Save this as
xblock_theme_check.pyin yourTUTOR_PLUGINS_ROOT:Enable it and rebuild:
You will also need to have openedx/openedx-platform#39178 and openedx/frontend-app-authoring#3271 bind-mounted in your stack.
document.querySelector('.xblock_html').getRootNode().constructor.namereturns"ShadowRoot". Note thatdocument.querySelector('.xblock-root')returnsnullby design - that container is created inside the shadow root anddocument.querySelectordoes not cross the boundary; reach it withdocument.querySelector('.xblock_html').shadowRoot.querySelector('.xblock-root').body { font-family: ... }and confirm the block does not inherit it. The author's own CSS stays inside the block for the same reason. Expect one deliberate exception: the theme stylesheets are appended todocument.headas well as to the shadow root, because Paragon declares its custom properties on:rootand:rootdoes not cross a shadow boundary - so seeing the theme on the rest of the page is intended, not a leak.<html>element carriesinclude_theme="true"; with it off, the attribute is absent - the serializer only writes the field when it is set, so the default never appears in OLX. This depends on fix: serialize the Text (HTML) XBlock's include_theme setting [WIP] openedx-platform#39178 - the serializer uses a hardcoded allowlist and silently drops the field without it.Other information
Merge checklist:
Check off if complete or not applicable:
Private ref: FAL-4394