Conversation
editor/index.php stubbed every preview-sw.js registration, so the editor always fell back to a blob: preview. There the inlined theme CSS keeps relative url(...) images that cannot resolve, and the style icons (page navigation, menu toggle, footer logo) disappeared from the preview. The wrapper now lets the registration through and only absorbs a failed one, which keeps proxied routers such as moodle-playground quiet. Related to exelearning/exelearning#2476.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #158 +/- ##
=========================================
Coverage 93.92% 93.92%
Complexity 810 810
=========================================
Files 46 46
Lines 3554 3554
=========================================
Hits 3338 3338
Misses 216 216
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the embedded editor's Preview, the style's icons were missing: the previous/next buttons and the menu toggle showed as plain coloured circles, and the footer logo was gone. It happened with every style: built-in, admin-uploaded and user-uploaded.
After this change, the preview shows the style exactly as the published activity does.
Original issue
Related to exelearning/exelearning#2476, reported by @ignaciogros. Thank you for the before/after images and for checking all three kinds of styles: that ruled out the styles themselves and pointed at the preview renderer.
Root cause
The editor renders its preview through a service worker,
preview-sw.js.editor/index.phpwrappednavigator.serviceWorker.registerand never let that worker register (it resolved a fake registration instead). The wrapper was added so a proxiedstatic.phprouter that 404s the script (moodle-playground) would not spam the console.Without the worker, the editor falls back to a
blob:URL. That fallback inlines the style's CSS but keeps its relativeurl(...)references, for examplebackground: … url(img/icons.png)for the navigation buttons. From ablob:URL those paths cannot resolve, so the background colour paints and the icon sprite does not.Fix
The wrapper now calls the real
register()and only absorbs a failure: it logs a warning and resolves the stub, so the editor still falls back quietly where the worker cannot be served. On a normal site the worker registers undereditor/static.php/<cmid>/viewer/(inside the script's own path, so noService-Worker-Allowedheader is needed) and the preview resolves every theme file.TDD
RED
tests/js/editor_service_worker_shim.test.jsextracts the service-worker block fromeditor/index.phpand runs it against a fakenavigator. Onmain:GREEN
Manual check: after opening the preview,
navigator.serviceWorker.getRegistrations()inside the editor returns…/editor/static.php/2/viewer/withpreview-sw.jsactive.How to test
Screenshots
Before
After
Notes
version.phpbump: onlyeditor/index.php(PHP) changes.Moodle Playground Preview
The changes in this pull request can be previewed and tested using a Moodle Playground instance.
ℹ️ The eXeLearning editor is fetched from the shared release and unpacked into the plugin when the playground boots, so the first load may take a few extra seconds. ELPX upload, viewer and preview work normally.