Skip to content

Commit 02cfa64

Browse files
sserrataclaude
andcommitted
fix(theme): apply default expansion depth even when control is hidden
`themeConfig.api.schemaExpansion.default` now reliably auto-expands to the configured depth on every page load when `enabled` is false — the provider previously kept reading from localStorage in that case, so a stale value from a prior session where the control was enabled could shadow the new default. Persistence is now implicitly off whenever the control is hidden. Also clarify the docstrings so it's discoverable that you can set just `{ default: 1 }` to get auto-expansion without rendering the UI. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent cdc2ed7 commit 02cfa64

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

packages/docusaurus-theme-openapi-docs/src/theme/SchemaExpansion/context.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ function readConfig(
6161
): SchemaExpansionConfig {
6262
const raw = themeConfig?.api?.schemaExpansion;
6363
if (!raw) return DEFAULT_CONFIG;
64+
const enabled = raw.enabled ?? false;
6465
return {
65-
enabled: raw.enabled ?? false,
66+
enabled,
6667
defaultLevel: normalizeLevel(raw.default),
6768
max: typeof raw.max === "number" && raw.max > 0 ? Math.floor(raw.max) : 4,
68-
persist: raw.persist ?? true,
69+
// Persistence only matters when the reader can change the level via the
70+
// UI control. When the control is hidden, fall back to the configured
71+
// default on every visit so it isn't shadowed by a stale localStorage
72+
// value from a session where the control used to be enabled.
73+
persist: enabled ? (raw.persist ?? true) : false,
6974
};
7075
}
7176

packages/docusaurus-theme-openapi-docs/src/types.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ export interface ThemeConfig {
3737
/**
3838
* Controls automatic expansion of nested schema trees in request/response
3939
* documentation. Inspired by Redoc's `schemaExpansionLevel`.
40+
*
41+
* `default` applies whether or not `enabled` is `true` — set
42+
* `{ default: 1 }` alone to auto-expand the first level on every page
43+
* without rendering the depth control.
4044
*/
4145
schemaExpansion?: {
42-
/** Show an interactive control on the page so readers can change depth at view time. Defaults to `false`. */
46+
/** Render an interactive depth control next to each schema header so readers can change the depth at view time. Defaults to `false`. */
4347
enabled?: boolean;
44-
/** Initial expansion depth. Use `"all"` to expand everything. Defaults to `0` (all collapsed). */
48+
/** Initial expansion depth applied on every page load. Use `"all"` to expand everything. Defaults to `0` (all collapsed). */
4549
default?: number | "all";
46-
/** Maximum depth value offered by the UI control's pill buttons. Defaults to `4`. */
50+
/** Highest numeric depth offered by the UI control. Ignored when `enabled` is `false`. Defaults to `4`. */
4751
max?: number;
48-
/** Persist the reader's selected depth in `localStorage`. Defaults to `true` when `enabled` is `true`. */
52+
/** Persist the reader's selected depth in `localStorage`. Only meaningful when `enabled` is `true`; defaults to `true` in that case. */
4953
persist?: boolean;
5054
};
5155
};

0 commit comments

Comments
 (0)