Skip to content

🐞 Patch Stoplight mosaic storage fallback#2416

Draft
JFWooten4 wants to merge 3 commits into
stellar:mainfrom
JFWooten4:2145-pt-42
Draft

🐞 Patch Stoplight mosaic storage fallback#2416
JFWooten4 wants to merge 3 commits into
stellar:mainfrom
JFWooten4:2145-pt-42

Conversation

@JFWooten4

Copy link
Copy Markdown
Contributor

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 removeItem support to Mosaic’s in-memory storage fallback, avoids reading document.documentElement when document is unavailable, and falls back to memory storage when localStorage.removeItem is missing.

This prevents Mosaic’s Zustand-backed theme store from failing when rendered in environments that do not provide a complete browser storage API.

Copilot AI review requested due to automatic review settings April 30, 2026 11:02

Copilot AI left a comment

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.

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 removeItem to Mosaic’s in-memory storage fallback.
  • Avoid reading document.documentElement when document is unavailable.
  • Fall back to in-memory storage when localStorage.removeItem is missing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread patches/@stoplight+mosaic+1.53.4.patch Outdated
Comment thread patches/@stoplight+mosaic+1.53.4.patch Outdated
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.
@ElliotFriend

Copy link
Copy Markdown
Contributor

I dug into this one: the bug is real (confirmed memoryStorage lacks removeItem in the installed mosaic 1.53.5) and your fix targets the right layer. Good find.

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:

  1. First step is an upstream issue at @stoplight/mosaic with your diagnosis — you did the work, you should get the credit. Happy to co-sign and add repo context.
  2. If upstream doesn't move in a reasonable window, we'll revisit this as a pnpm patch against the then-current version, with the upstream issue linked from the patch so we know when we can delete it.

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.

@JFWooten4

Copy link
Copy Markdown
Contributor Author

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 patch-package file became inert after the pnpm migration, I will not convert it into a pnpm patch unless upstream stalls and we decide that carrying the fix locally is warranted. I’ll leave this PR open for tracking as requested.

@JFWooten4
JFWooten4 marked this pull request as draft July 14, 2026 08:30
@ElliotFriend

Copy link
Copy Markdown
Contributor

thanks @JFWooten4!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants