Skip to content

memoryStorage theme fallback does not implement removeItem #2945

Description

@JFWooten4

Package

@stoplight/mosaic@1.53.5

Problem

The in-memory storage fallback used by Mosaic’s persisted theme store implements getItem and setItem, but not removeItem.

When Mosaic selects this fallback because browser storage is unavailable, clearing the persisted theme value can fail because the storage object does not satisfy the complete interface expected by the persisted store.

The fallback currently has the equivalent of:

const memoryStorage = {
  getItem: name => memoryDb[name],
  setItem: (name, value) => {
    memoryDb[name] = value;
  },
};

Expected behavior

The memory fallback should support removing a stored value:

const memoryStorage = {
  getItem: name => memoryDb[name],
  setItem: (name, value) => {
    memoryDb[name] = value;
  },
  removeItem: name => {
    delete memoryDb[name];
  },
};

It may also be useful for the theme-storage selector to verify that the selected localStorage implementation provides removeItem, rather than checking only whether localStorage is defined.

Downstream context

This was encountered while rendering Stellar API documentation in environments that do not provide a complete browser storage implementation.

A downstream patch was prepared in stellar/stellar-docs#2416, but the project would prefer to resolve the defect upstream rather than maintain a package patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions