Repository navigation
fix(docui): load Redoc v3 as an ES module, keep v2 with WithRedocV2 - #552
Merged
Merged
Conversation
Redoc v3 ships its standalone bundle as an ES module, and the "latest" CDN URL now serves it. Loaded with a classic <script src>, it fails with "Cannot use 'import.meta' outside a module" and the page stays blank. The default Redoc template now uses <script type="module">, and the default bundle URL is pinned to redoc@3 on jsdelivr instead of "latest". The v2 bundle does not load as a module: its UMD wrapper reads properties of the top-level "this", which is undefined in a module. WithRedocV2 restores the classic template and defaults the URL to redoc@2. The deprecated middleware.RedocOpts gets a matching RedocV2 field. Users who set WithUIAssetsURL to a v2 bundle must add WithRedocV2. Fixes #550 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #552 +/- ##
==========================================
+ Coverage 87.10% 87.14% +0.04%
==========================================
Files 65 65
Lines 4752 4762 +10
==========================================
+ Hits 4139 4150 +11
Misses 602 602
+ Partials 11 10 -1 ☔ View full report in Codecov by Harness. |
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.
Fixes #550.
Problem
docui.Redocloaded its bundle fromhttps://cdn.redoc.ly/redoc/latest/..., which now serves Redoc 3.0.1. The v3 standalone bundle is an ES module: it ends withexport{RedocStandalone,hydrate,init}and usesimport.meta. Our template loaded it with a classic<script src>, so the browser threwUncaught SyntaxError: Cannot use 'import.meta' outside a moduleand the page stayed blank.Fix
<script type="module">. v3 still finds the<redoc spec-url=...>element on load and callsinit, so nothing else in the template changes.https://cdn.jsdelivr.net/npm/redoc@3/bundles/redoc.standalone.jsinstead oflatest, so a future major release cannot break the page again. (cdn.redoc.ly/redoc/v3/...returns 403; jsdelivr resolves@3to the latest v3.)docui.WithRedocV2(). It restores the classic-script template and defaults the URL toredoc@2.WithUITemplateandWithUIAssetsURLstill override both, in any argument order.middleware.RedocOptsgets aRedocV2field mapped toWithRedocV2(), for callers ofmiddleware.Redoc.Why v2 needs an option
type="module"breaks the v2 bundle. Its UMD wrapper is!function(e,t){... e.Redoc=t(e.null)}(this, ...). In a module, top-levelthisisundefined, soe.nullthrows before Redoc starts.Compatibility
WithUIAssetsURL(orRedocOpts.RedocURL) pointing at a v2 bundle with the default template: worked before, now renders blank. AddWithRedocV2()(orRedocV2: true). This needs a release note.Verification
Besides the unit tests, I rendered the pages in headless Chromium against a small spec: the default page (v3) and the
WithRedocV2()page (v2) both render it. The classic template with the v3 bundle renders nothing, which reproduces the bug.🤖 Generated with Claude Code