Skip to content

Make clearing TypeDoc fields from local storage optional #2908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions site/development/local-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ To enable local storage, use:
`window.TypeDoc.enableLocalStorage();`

**Note:** Local storage is enabled by default.

To disable local storage without clearing it, use:

`window.TypeDoc.disableWritingLocalStorage();`
4 changes: 4 additions & 0 deletions src/lib/output/themes/default/assets/typedoc/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ declare global {
[k: `kind_${number}`]: string;
};
TypeDoc: {
disableWritingLocalStorage: () => void;
disableLocalStorage: () => void;
enableLocalStorage: () => void;
};
}
}

window.TypeDoc ||= {
disableWritingLocalStorage() {
storage.disableWritingLocalStorage();
},
disableLocalStorage: () => {
storage.disable();
},
Expand Down
3 changes: 3 additions & 0 deletions src/lib/output/themes/default/assets/typedoc/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ try {
export const storage = {
getItem: (key: string) => _storage.getItem(key),
setItem: (key: string, value: string) => _storage.setItem(key, value),
disableWritingLocalStorage() {
_storage = noOpStorageImpl;
},
disable() {
localStorage.clear();
_storage = noOpStorageImpl;
Expand Down