🐞 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.
Move getThemeStorage above defaultMode so defaultMode cannot reference the const helper before it is initialized. This keeps the storage-backend alignment fix while avoiding a fragile declaration order in the patched Mosaic bundles.
|
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!! |
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.