Skip to content

Add support for disabling local storage usage #2872

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
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ title: Changelog

## Unreleased

## v0.27.9 (2025-02-25)

This will be the last v0.27.x release, see #2868 for discussion on the 0.28 beta.

### Features

- Added support for TypeScript 5.8

## v0.27.8 (2025-02-21)

### Features
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "typedoc",
"description": "Create api documentation for TypeScript projects.",
"version": "0.27.8",
"version": "0.27.9",
"homepage": "https://typedoc.org",
"type": "module",
"exports": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"yaml": "^2.6.1"
},
"peerDependencies": {
"typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x"
"typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x"
},
"devDependencies": {
"@types/lunr": "^2.3.7",
Expand All @@ -49,7 +49,7 @@
"puppeteer": "^23.6.1",
"semver": "^7.6.3",
"tsx": "^4.19.2",
"typescript": "5.7.2",
"typescript": "5.8.1-rc",
"typescript-eslint": "^8.15.0"
},
"files": [
Expand Down
1 change: 1 addition & 0 deletions site/development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ children:
- themes.md
- internationalization.md
- third-party-symbols.md
- local-storage.md
---

# Development
Expand Down
19 changes: 19 additions & 0 deletions site/development/local-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Disabling Local Storage
---

# Disabling Local Storage

TypeDoc uses local storage by default to retain operational state information across page loads for components such as side menus, site menus, and generated pages. To comply with certain functional cookie requirements, local storage usage can be toggled using the `window.TypeDoc` object.

To disable local storage, use:

`window.TypeDoc.disableLocalStorage();`

**Note:** Disabling local storage will clear its contents.

To enable local storage, use:

`window.TypeDoc.enableLocalStorage();`

**Note:** Local storage is enabled by default.
2 changes: 1 addition & 1 deletion site/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ the supported version range will generally not include versions not supported by

| TypeDoc Version | TypeScript Version | Status |
| --------------- | ------------------ | ------------------- |
| 0.27 | 5.0 through 5.7 | ✅ Maintained |
| 0.27 | 5.0 through 5.8 | ✅ Maintained |
| 0.26 | 4.6 through 5.6 | ⚠️ Security Updates |
| 0.25 | 4.6 through 5.4 | ❌ Unmaintained |
| 0.24 | 4.6 through 5.1 | ❌ Unmaintained |
Expand Down
14 changes: 14 additions & 0 deletions src/lib/output/themes/default/assets/typedoc/Application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IComponentOptions } from "./Component.js";
import { storage } from "./utils/storage.js";

declare global {
interface Window {
Expand All @@ -13,9 +14,22 @@ declare global {
folder: string;
[k: `kind_${number}`]: string;
};
TypeDoc: {
disableLocalStorage: () => void;
enableLocalStorage: () => void;
};
}
}

window.TypeDoc ||= {
disableLocalStorage: () => {
storage.disable();
},
enableLocalStorage: () => {
storage.enable();
},
};

// For debugging with a watch build
window.translations ||= {
copy: "Copy",
Expand Down
32 changes: 24 additions & 8 deletions src/lib/output/themes/default/assets/typedoc/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,31 @@ export interface MinimalStorage {

let _storage: MinimalStorage;

const noOpStorageImpl: MinimalStorage = {
getItem() {
return null;
},
setItem() {},
};

let localStorageImpl: MinimalStorage;

try {
_storage = localStorage;
localStorageImpl = localStorage;
_storage = localStorageImpl;
} catch {
_storage = {
getItem() {
return null;
},
setItem() {},
};
localStorageImpl = noOpStorageImpl;
_storage = noOpStorageImpl;
}

export const storage = _storage;
export const storage = {
getItem: (key: string) => _storage.getItem(key),
setItem: (key: string, value: string) => _storage.setItem(key, value),
disable() {
localStorage.clear();
_storage = noOpStorageImpl;
},
enable() {
_storage = localStorageImpl;
},
};
1 change: 0 additions & 1 deletion src/lib/output/themes/default/partials/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export function settings(context: DefaultThemeRenderContext) {
}

// Settings panel above navigation

return (
<div class="tsd-navigation settings">
<details class="tsd-accordion" open={false}>
Expand Down