🐞 Patch Stoplight mosaic storage fallback - #2416
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a patch-package patch for @stoplight/mosaic@1.53.4 to make Mosaic’s theme persistence more resilient in SSR/non-browser and partial Storage API environments.
Changes:
- Add
removeItemto Mosaic’s in-memory storage fallback. - Avoid reading
document.documentElementwhendocumentis unavailable. - Fall back to in-memory storage when
localStorage.removeItemis missing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I dug into this one: the bug is real (confirmed But I'm going to hold off on merging a package patch here. A repo policy I'd like to propose: dependency patches are a last resort — they freeze us to a version, they don't get upstream fixes, and they rot silently (case in point: the repo's move to pnpm in #2493 left this PR's patch-package file inert, which is why CI is green — it currently changes nothing). Path forward:
The failure mode this fixes (broken storage in private browsing on API pages) is low-severity enough that we lose little by sequencing it this way. I'll leave this open for now with a note; if you file the upstream issue, link it here. |
|
Thanks for digging into this. I agree with treating dependency patches as a last resort. I filed the upstream issue here: stoplightio/elements#2945 Since the existing |
|
thanks @JFWooten4!! |
Migrate the Mosaic storage fallback patch to pnpm patchedDependencies and regenerate the pnpm lockfile against @stoplight/mosaic@1.53.5. Co-authored-by: Codex Web <noreply@openai.com>
|
Quick follow-up: upstream issue stoplightio/elements#2945 is still open and hasn’t received a maintainer response. I followed up there on August 10 asking whether I rechecked this against current I also validated the pnpm-patched build end-to-end: the patch applies successfully and the build completes without the |
Regenerate pnpm-lock.yaml after the Mosaic patch changes so frozen-lock installs remain valid. Co-authored-by: Codex Web <noreply@openai.com>
Validate the full storage interface and fall back to memory storage when localStorage access throws. Co-authored-by: Codex Web <noreply@openai.com>
Co-authored-by: Codex Web <noreply@openai.com>
The Mosaic patch hash has been regenerated in pnpm-lock.yaml, so the one-off workflow is no longer needed. Co-authored-by: Codex Web <noreply@openai.com>
In a similar spirit to #2415, this PR fixes working environments where memory cleanup struggles. It applies a root-clear fix to actually delete the requested data. This same error fix sometimes fixes the warning while actually applying the intent, acting as a first line of defense against the build error.
Changes
This patch makes Stoplight Mosaic’s theme persistence safer in non-browser and partial-storage environments.
It adds
removeItemsupport to Mosaic’s in-memory storage fallback, avoids readingdocument.documentElementwhendocumentis unavailable, and falls back to memory storage whenlocalStorage.removeItemis missing.This prevents Mosaic’s Zustand-backed theme store from failing when rendered in environments that do not provide a complete browser storage API.