Skip to content

fix(docui): load Redoc v3 as an ES module, keep v2 with WithRedocV2 - #552

Merged
fredbi merged 1 commit into
masterfrom
fix/550-redoc-v3
Oct 28, 2026
Merged

fredbi merged 1 commit into
masterfrom
fix/550-redoc-v3

Conversation

@fredbi

@fredbi fredbi commented Oct 28, 2026

Copy link
Copy Markdown
Member

Fixes #550.

Problem

docui.Redoc loaded its bundle from https://cdn.redoc.ly/redoc/latest/..., which now serves Redoc 3.0.1. The v3 standalone bundle is an ES module: it ends with export{RedocStandalone,hydrate,init} and uses import.meta. Our template loaded it with a classic <script src>, so the browser threw Uncaught SyntaxError: Cannot use 'import.meta' outside a module and the page stayed blank.

Fix

  • The default Redoc template now uses <script type="module">. v3 still finds the <redoc spec-url=...> element on load and calls init, so nothing else in the template changes.
  • The default bundle URL is pinned to https://cdn.jsdelivr.net/npm/redoc@3/bundles/redoc.standalone.js instead of latest, so a future major release cannot break the page again. (cdn.redoc.ly/redoc/v3/... returns 403; jsdelivr resolves @3 to the latest v3.)
  • New option docui.WithRedocV2(). It restores the classic-script template and defaults the URL to redoc@2. WithUITemplate and WithUIAssetsURL still override both, in any argument order.
  • The deprecated middleware.RedocOpts gets a RedocV2 field mapped to WithRedocV2(), for callers of middleware.Redoc.
  • Doc site: new default URL, plus a short "Redoc v2" section and a row in the shim mapping table.

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-level this is undefined, so e.null throws before Redoc starts.

Compatibility

  • Default settings: already broken on v3; fixed by this PR.
  • Custom template: unchanged.
  • WithUIAssetsURL (or RedocOpts.RedocURL) pointing at a v2 bundle with the default template: worked before, now renders blank. Add WithRedocV2() (or RedocV2: 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

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

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.14%. Comparing base (80fa728) to head (8bb9918).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@fredbi
fredbi merged commit 9ef9fed into master Oct 28, 2026
36 checks passed
@fredbi
fredbi deleted the fix/550-redoc-v3 branch October 28, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redoc v3 release breaks defaul values

1 participant