[WIP] fix: prevent XBlock container crash when JS resources are blocked by browser extensions#38575
[WIP] fix: prevent XBlock container crash when JS resources are blocked by browser extensions#38575bra-i-am wants to merge 1 commit intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @bra-i-am! 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. |
Description
Fixes a resilience bug in Studio's XBlock container page where Chrome extensions (e.g. AdBlock) that block certain JS resources cause an infinite loading spinner and crash the entire container page — preventing all XBlocks in the unit from rendering, not just the one whose resource was blocked.
Affected user role: Course Authors using Chrome with content-blocking extensions.
Root causes fixed:
loadResourceusedViewUtils.loadJavaScript(backed by$script/scriptjs), which calls its callback on bothonloadandonerror. When AdBlock blocks a script, the promise always resolved — making failures invisible to the application. Fixed by replacing it with a raw<script>element that wiresonerror → rejectdirectly.addXBlockFragmentResourcesaborted on first JS failure, skipping all subsequent resources in the list. A vertical fragment's resource list is shared across all child XBlocks. Aborting early prevented unrelated XBlocks (Problem, Video, etc.) from loading their resources, cascading the failure across the entire unit. Fixed by always continuing to the next resource regardless of failure.constructBlockincore.jscrashed withTypeErrorwhen an XBlock's init function was undefined (because its JS never loaded). The crash propagated to the outertry/catchinhandleXBlockFragment, which callederrorCallback()instead ofsuccessCallback()— leaving the container page stuck. Fixed by adding a null check that marks only the affected XBlock asxblock-initialization-failedand returns a stub, allowing the rest of the vertical to initialize normally.container.jsmessage handler logged a spurious warning loop for everypostMessageevent withtype: undefinedsent by browser extension proxies (e.g. Redux DevTools) viasetInterval. Fixed by only logging for defined, unrecognized message types.Behavior after this fix:
xblock-initialization-failedCSS class. Their JS is not initialized, so interactive behavior (e.g. drag and drop) is unavailable — but the block is visible and the page does not crash.console.warnis emitted for each blocked resource and each skipped init function, replacing the previous silent freeze.Before: Chrome + AdBlock → infinite spinner,
TypeError: Cannot read properties of undefined (reading 'prototype'), all XBlocks in the unit broken.After: Chrome + AdBlock → affected XBlock shows its default loading state, all other XBlocks render and initialize normally, no JS crash.
Supporting information
eduNEXT/edx-platform, branchnau/teak.master).$script/scriptjs issue withonerroris a known limitation of that library: it does not distinguish between successful load and network/block failure.Testing instructions
Prerequisites: Chrome browser with uBlock Origin or AdBlock Plus installed and active. A Studio course unit containing a Drag & Drop v2 XBlock alongside at least one other XBlock type (e.g. Problem/Single Select).
Steps:
console.warnmessages:Failed to load XBlock resource: .../virtual-dom-1.3.0.min.jsandXBlock init function not found: DragAndDropBlock.TypeError: Cannot read properties of undefined (reading 'prototype').TypeErrorcrash.Also verify: With AdBlock disabled, the page behaves identically to before this change — no regression for users without content blockers.
Deadline
None.
Other information
window.failedXBlockResourcesglobal is introduced alongside the existingwindow.loadedXBlockResourcespattern to track resource hashes that have previously failed, preventing redundant network requests for known-bad resources on subsequent XBlock renders within the same page session./container/...). The authoring MFE embeds this page in an iframe and is also covered by this fix.