Skip to content

fix(web): guard persisted stores when localStorage is unavailable - #692

Closed
KLIEBHAN wants to merge 2 commits into
pingdotgg:mainfrom
KLIEBHAN:pr/safe-browser-storage
Closed

KLIEBHAN wants to merge 2 commits into
pingdotgg:mainfrom
KLIEBHAN:pr/safe-browser-storage

Conversation

@KLIEBHAN

@KLIEBHAN KLIEBHAN commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Guard persisted web stores when localStorage is unavailable or unusable.

Why

Some environments throw either when reading localStorage or when calling its methods. The original fallback also used a module-level in-memory store, which can leak state across server-side requests. This update switches to per-call in-memory fallback storage and permanently falls back after the first storage access failure.

Testing

  • bun x vitest run apps/web/src/lib/browserStorage.test.ts
  • bun lint
  • bun typecheck

Note

Guard web composer and terminal persisted stores by using getSafeLocalStorage to handle unavailable localStorage

Introduce getSafeLocalStorage with in-memory failover and update zustand persist stores to use it; add tests and a createMemoryStorage utility.

📍Where to Start

Start with getSafeLocalStorage in apps/web/src/lib/browserStorage.ts.

Macroscope summarized 1964131.

@KLIEBHAN KLIEBHAN changed the title fix(web): guard persisted stores when localstorage is unavailable fix(web): guard persisted stores when localStorage is unavailable Mar 9, 2026
@github-actions github-actions Bot added the vouch:unvouched Author is not yet trusted in the VOUCHED list. label Mar 9, 2026
@coderabbitai

coderabbitai Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 90c0549f-a010-4c4b-9999-76ffdae02c48

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

);
}

export function getSafeLocalStorage(): Storage {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low lib/browserStorage.ts:40

memoryStorageEntries is a module-level Map shared across all server-side requests. When getSafeLocalStorage falls back to memoryStorage on the server, data written by one request persists and leaks to subsequent requests from other users. Consider creating a fresh storage instance per call, or throw in server environments to prevent accidental usage.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/web/src/lib/browserStorage.ts around line 40:

`memoryStorageEntries` is a module-level `Map` shared across all server-side requests. When `getSafeLocalStorage` falls back to `memoryStorage` on the server, data written by one request persists and leaks to subsequent requests from other users. Consider creating a fresh storage instance per call, or throw in server environments to prevent accidental usage.

Evidence trail:
apps/web/src/lib/browserStorage.ts (REVIEWED_COMMIT):
- Line 1: `const memoryStorageEntries = new Map<string, string>();` - module-level Map
- Lines 3-20: `memoryStorage` object uses this shared Map
- Lines 40-58: `getSafeLocalStorage()` returns `memoryStorage` when `globalThis.localStorage` is unavailable (server-side case)

@juliusmarminge

Copy link
Copy Markdown
Member

Closing as part of backlog cleanup: this PR is stale, currently conflicting with main, has no approval, and has not had active remediation for 30+ days. If the change is still relevant, please rebase onto current main and request reopening or submit a focused current diff. Thank you for the contribution.

@KLIEBHAN
KLIEBHAN deleted the pr/safe-browser-storage branch November 12, 2026 09:43
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
…ed time (pingdotgg#692)

A stored rule order can hold fewer than three rules, or none, and the
lastCalled shape time can be 0. Pin that only rules in the order are used,
an empty order shows the Default Icon, and a 0 time holds at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
…ck-fixtures

test(bots): icon rule fields in test fixtures (pingdotgg#692)
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
Add resolveBotIcon, a pure evaluator that picks a Bot's timeline image or
rule shape from its icon rules, with the next moment the result can change,
and botLeftForYouSinceMs for the leftOnDelivered minute 0. Add the start
time parser and short formatter for the editor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
A thread never visited now counts as read for leftOnDelivered, through the
same unread check the Bot list uses. resolveBotIcon no longer takes the
Bot's status, since each rule's start time already says whether it applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
…ed time (pingdotgg#692)

A stored rule order can hold fewer than three rules, or none, and the
lastCalled shape time can be 0. Pin that only rules in the order are used,
an empty order shows the Default Icon, and a 0 time holds at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
BotAvatar now resolves a Bot's icon rules wherever it knows the Bot: a
timeline image or rule shape replaces the Default Icon in the one slot,
re-resolved once at each boundary instead of on a tick. The next timeline
image loads ahead, and a stored image stays up until the next one loads.
Muted Bots keep their Default Icon, now grayed out. Editors opt out.

The roster's workingSince, deliveredAt and erroredAt now reach the client
through ScopedBotEntry, and botIconInputs turns them and the Bot thread's
shell into each rule's minute 0. The evaluator uses the contract types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
feat(bots): icon rules storage and roster timestamps (pingdotgg#692)
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
✨ feat(bots): resolve and show Bot icons from their rules (pingdotgg#692)
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
Count unreadable icon times as a change, so Discard and the close prompt
apply. Gate Save only on the mode the draft Default Icon turns on, and
send a hidden mode with a problem as saved. Refresh the editor's now
badge elapsed time once a minute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
✨ feat(bots): edit a Bot's icon timeline in settings (pingdotgg#692)
notFrost added a commit to d3labs-dev/t3code that referenced this pull request Dec 1, 2026
🐛 fix(bots): keep missing saved timeline images and center time fields (pingdotgg#692)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants