Skip to content

Applying a keyed answer in a derived optimistic store changes the source store (CS-R4) #5139

Open

Description

@GabbeV

Describe the bug

CS-R4 says that a write through a derived store stays in that view and leaves upstream stores untouched. CS-R3 explicitly includes optimistic stores in this boundary. The #4996 ruling confirms the distinction from plain stores.

Here the derived store borrows a row, then its derivation assigns a fresh object with the same key. That assignment changes the source row too.

const [source] = createStore([{ id: 1, value: 0 }]);
const [answer, setAnswer] = createSignal<Row>();
const [derived, guess] = createOptimisticStore((draft: Row[]) => {
  const row = answer();
  if (row) draft[0] = row;
}, [], { key: "id" });

function run() {
  guess(() => [source[0]]);
  setAnswer({ id: 1, value: 1 });
}

The source setter is never called.

Your Example Website or App

https://s.olid.uk/id/dp7DlXyKTYiS7MKkq4ii_Q

Steps to Reproduce the Bug or Issue

  1. Open the example. Source shows 0 and Derived is empty.
  2. Click Run. Both show 1.

Expected behavior

Source should still show 0 and Derived should show 1.

Screenshots or Videos

No response

Platform

Solid 2.0.1, Chromium

Additional context

On main at b884d6e, temporarily bypassing the foreign-proxy pairing call in pairRows makes both the synchronous example and the version with an open action show the expected values. Related to #4903.

Activity

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

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