Repository navigation
feat: port to Redoc 3 (3.0.1) - #2
Open
ramseydsilva wants to merge 11 commits into
Open
ramseydsilva wants to merge 11 commits into
ramseydsilva wants to merge 11 commits into
Conversation
Render Redoc 3 in the browser, route its sub-paths by URL path, map old Redoc 2 `#tag/...` links to path links, and keep its color mode in step with Docusaurus. Redoc 3 removes the Redoc 2 internals the theme was built on and routes by path instead of hash, so this is a port, not a version bump. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every tag and operation is rendered to its own static page, with one exact route each. Unknown paths below an API are a 404 and links to them are checked at build time. The `ssr` option is `true` by default; `'required'` fails the build if a page cannot be rendered, and `false` turns it off. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Resolve react-router for Redoc, fix the base path of an embedded API, and clean up lint, types and engines. Split the plugin entry. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…urus theme Redoc 3 sends usage events unless `disableTelemetry` is set, so it is on by default here. Map the Docusaurus theme to Redoc's CSS variables (fonts, colors, light and dark), with `primaryColor`, `primaryColorDark` and a `cssVariables` option to override them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Tests use Node's built-in runner. The downloadable spec is kept as written when operationIds are trimmed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…s in dev The spec download uses Redoc 3's `downloadUrls`. An embedded API is stacked instead of squeezing three columns into a docs page. Exact routes are registered in the dev server and in other locales too. Document the network requests Redoc 3 makes. Declare react and react-dom as peers and add @redocly/config. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Everything that relies on Redoc's undocumented color mode behaviour is in one place, with a test that reads the installed Redoc. `syncColorMode: false` turns it off. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Reloading a link inside an embedded API returns a 404, because the page that embeds it has no route for the sub-path. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
|
@claude review |
…adings on narrow screens A relative download URL was read against the tag or operation page, so the link was a 404 there. On screens up to 600px the title and section headings use smaller sizes, so a word is not broken in the middle. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Path routing gives one static page per tag and operation. A hash router gives one page per spec and every link into it is flagged by the broken-anchor check. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Remounting Redoc on every mode change rebuilt the whole page: it scrolled to the top and its height changed. Click Redoc's own color mode switcher instead, which changes the mode in place, and keep the remount only as the fallback for when the switcher is not on the page. Add tests that check the installed Redoc still has the switcher and toggles dark and light. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
Ports redocusaurus from Redoc 2.4 to Redoc 3.0.1 (tracking #473). This is a port, not a version bump: Redoc 3 removes the Redoc 2 internals the theme was built on (
AppStore,OperationModel,Section, mobx,redoc/typings/*), ships as a browser-only ES module, routes by URL path instead of hash, and is themed with CSS variables instead of athemeobject.This is a staging PR in the fork, to review the change and agree the shape of it before proposing it upstream. The checklist at the end tracks what is left before that.
What changed
redoc2.4.0 → 3.0.1,@redocly/openapi-core1.16 →^2.BrowserOnly.ServerRedoc,ServerStyles,Styles,useSpec,ApiOperationandApiSchemaare removed.ssroption, defaulttrue): Redoc 3 can't berequired from Node, so the plugin renders each spec in a worker thread with Redoc 3's own server API. Every tag and operation gets its own exact route and static HTML, with a shared stylesheet per spec.ssr: 'required'fails the build if a spec can't be rendered. HTML is rendered only for production builds of the default locale. The dev server and other locales get the same exact routes (so a path that is not a page is a "Page Not Found" everywhere and links are checked), rendered in the browser. Because every page is a real file, hosts need no fallback rule for deep links and unknown paths are real 404s. Redoc replaces the server HTML when it mounts (it does not hydrate it).basePath. Embedded pages (<ApiDocMdx>,@theme/Redocin a custom page) use the right base.specUrl. The spec's download link (the bundled copy, or its ownurl) is now passed as Redoc 3'sdownloadUrls, in the browser and in the build-time render. A relativeurlis relative to the site'sbaseUrl, or withnormalizeUrl: falseto the API'sroute(never to the page the reader is on, because Redoc 3 reads a relative URL against each tag and operation page, and the Copy menu's "Open in Claude/ChatGPT" prompt would link to a 404).<ApiDocMdx>used a Redoc 2 breakpoint override that Redoc 3 ignores, which left the three columns squeezed into the docs column. It now setslayout: 'stacked'as a default that a site's ownlayoutoverrides.utils/legacyHash.tsredirects Redoc 2#tag/<Tag>and#tag/<Tag>/operation/<id>hashes to the new path URLs in the browser.#operation/...,#section/...and#schema/...are not handled.themeoption. The API pages now follow the Docusaurus theme by default: Redoc's tokens are set from Infima variables, in light and dark mode.primaryColorandprimaryColorDarkset the primary tokens, and a newcssVariables: { light, dark }option sets any other token. The Redoc 2themeobject is ignored, with one warning per build. On screens up to 600px wide the page title and section headings use smaller sizes (Redoc's 36px title leaves no room next to its Copy button on a phone and a word is broken in the middle; a site's owncssVariablesstill win). In production the stylesheet is a small linked file (Docusaurus doesn't render<style>from<Head>into static HTML), in dev it's a<style>tag.otel.cloud.redocly.comunlessdisableTelemetryistrue. The theme now sets it totrueby default (override withdisableTelemetry: false), and the build-time render does too. This differs from Redoc's own default, so I'd like to confirm it.operationIdwhitespace is trimmed, with a warning, for the rendered pages only. The downloadable spec stays as written.localStorage['redoc.colorMode'], alight/darkclass on<html>) and ignores Docusaurus'sdata-theme. The theme syncs both ways and restores the class after navigation. When the Docusaurus mode changes, Redoc's own mode switch is clicked, so Redoc changes in place and the page keeps its scroll position; remounting Redoc is only the fallback if that switch is not on the page. This relies on Redoc internals, not a documented API, so it lives in one module, can be turned off withsyncColorMode: false, and a test checks the installed Redoc still behaves that way.react-router^7.0.0is declared, with a webpack rule that resolves it from Redoc's own location for Redoc's files only. Docusaurus makes@docusaurus/core's react-router 5 win for every import in the bundle, which broke Redoc.yarn test:unit, run in the build workflow), a changeset (a major bump for the three linked packages), a migration guide (website/docs/guides/migrating-to-v3.md), localtypes/redoc-compat.tsin place of the removed Redoc typings, andengines.node>=22.2.6.0-redoc3.Nis only for local packs. The changeset sets the real version, and the local version commits are dropped before submitting.Known limitations
<ApiDocMdx>in an MDX page and to@theme/Redocor@theme/ApiDocin a custom page. Redoc 3 routes by path below the page it is on, and a page of your own has no routes below it, so after clicking around inside the page, a reload (or a copied link) to an operation gives a 404. Redoc 2's hash links survived a reload. APIs with their ownrouteare not affected: every tag and operation is a static page. It is documented in the migration guide and in "Showing Multiple APIs". Options if you want it fixed: a hash router for embedded APIs (links like/docs/nested/nested-1#/pet/getpetbyid), which I have not tried.cdn.redoc.lyand cannot be turned off, but it hides itself if blocked. See the network requests guide.Breaking changes / requirements
>=22.reactandreact-dom18.3+ or 19 (already in every Docusaurus site).react-router7 andstyled-components6 are installed for Redoc, next to the versions Docusaurus uses.#tag/Accounts/operation/getBillingAccounts→/accounts/getbillingaccounts(lowercased). The browser redirect covers tag and operation hashes, not the rest.themeoption andtheme.openapi.themeinredocly.yamlno longer have an effect.ApiOperation,ApiSchema,ServerRedocandServerStylesare removed.See the migration guide for details.
Testing
faster/Rspack bundler). Checked with a sub-pathbaseUrl,trailingSlashtrueandfalse, OpenAPI 3.x, Swagger 2.0 JSON, multi-file YAML, a remote URL spec, several specs on one site, and embedded pages.ssroption validation and the plugin's route registration against the real Redoc 3 renderer.Path to upstream readiness
Checklist for going from this staging PR to the PR against
rohit-gohri/redocusaurus. Details and notes are tracked inREDOC3.mdon this branch, which is deleted before submitting.Coordination
next) or a major versionRequired for any PR
Functional
operationIdtrimming that doesn't change the downloadable specsyncColorModetheme option to turn it off, and a test that fails if a Redoc upgrade changes what it relies onbaseUrl, bothtrailingSlashsettings, OpenAPI 3.x and Swagger 2.0, remote and multi-file specs, several specs, embedded pages, the dev server and other locales (en,fr,ja). One known limitation, belowreactandreact-dom(^18.3.0 || ^19.0.0, Redoc's range) are peers of the theme and the preset,react-router^7.0.0stays a dependency (Docusaurus core depends on react-router 5, so a peer on 7 would conflict),@redocly/config(a types-only peer of Redoc) is a theme dependency, and unused Redoc 2 dependencies were removed. Checked with a strict-layout install; pnpm itself not testedcdn.redoc.ly) by default, with no option to turn it off but it hides itself if blocked; icon sets and telemetry only on demand; documented with CSP directives in a new guide (website/docs/guides/network-requests.md)Decisions to document
ssron by default (true): a failed render warns and falls back,'required'fails the buildoperationIdwhitespace: trimmed with a warning (rendered pages only)Packaging (final stage)
main: squash the checkpoint commits, set the commit identity, drop the local version commits (done: the history is 11 commits on top of upstreammainwith the public identity; still to do: drop the local version bumps)yarn.lockfrom upstream's and keep only the changes the port needs🤖 Generated with Claude Code