solid-primitives icon indicating copy to clipboard operation
solid-primitives copied to clipboard

multiplexStorage source of truth

Open developerdizzle opened this issue 6 months ago • 7 comments

Describe the bug

The docs for multiplexStorage state

For the getItem operation, the first storage that returns a valid value will be the source of truth.

But I am able to reproduce a scenario where the first storage has no value, the second storage has a value, but the value from the second storage is not used as the source of truth.

Steps to repro:

  1. Navigate to https://playground.solidjs.com/anonymous/f998757e-6b08-4054-9e7a-87a0b20902a7
  2. Verify that the counter button is set to 1
  3. Click the counter button once, incrementing it to 2
  4. Verify that the count in localStorage has been set to 2Image
  5. Verify that the count in indexedDB/localForage has been set to 2Image
  6. Refresh the page
  7. Verify that the counter button is still correctly set to 2
  8. Delete the localStorage record for count
  9. Refresh the page
  10. Verify that the counter button is incorrectly set back to 1
  11. Verify that the count in indexedDB/localForage is still set to 2

This seems to show that the localForage storage option is not being used, despite being the only storage option returning a valid value.

Minimal Reproduction Link

https://playground.solidjs.com/anonymous/f998757e-6b08-4054-9e7a-87a0b20902a7

developerdizzle avatar Jun 27 '25 03:06 developerdizzle

Thanks for your feedback!

null is a valid return value for Storage.getItem, so this is technically specified behaviour, albeit not specifically documented. However, I understand the issue and want to introduce better control over what should be the source of truth especially in case of deletion. I still need to think about the patterns that I want to use for that.

atk avatar Jun 29 '25 12:06 atk

Would undefined be considered an invalid return value? I could work around that issue by creating a new Storage wrapper around localStorage that returns undefined instead of null.

developerdizzle avatar Jun 30 '25 14:06 developerdizzle

This is not yet implemented, but I intend to change it in any case.

atk avatar Jun 30 '25 16:06 atk

Just to clarify, is there currently any way to return an invalid value? Would throwing an Error work?

developerdizzle avatar Jun 30 '25 17:06 developerdizzle

Just tested it. Unfortunately, no. I'll push this higher up on my to-do list.

atk avatar Jun 30 '25 20:06 atk

Just checking in - anything I can do to help get this going? @atk

developerdizzle avatar Aug 07 '25 12:08 developerdizzle

This requires some careful planning. I do not want to break backwards compatibility, so I need a format that keeps the current behavior and at the same time enables different behaviors.

atk avatar Oct 16 '25 07:10 atk