Skip to content

2.0.0-beta.25 | createProjection(()=>store) projection is not updating when store is mutated. #2941

Description

@mizulu

Describe the bug

returning a store top level, in a projection createProjection(()=>store)
creates a projection that does not update, when the store is updated.

if the store is nested in the projection, the project will update when the store updates

createProjection(()=>[store])
createProjection(()=>{somekey:store})
import { render } from '@solidjs/web';
import { createProjection, createStore } from 'solid-js';


const [store, setStore] = createStore(() => {
  return { a: 1, }
}, {} as { a: number })


let storeProjection = createProjection(
  () => {
    return store
  }, {}
)

let storeProjection2 = createProjection(
  () => {
    return {nested:store}
  }, {}
)

// update store in 1s 
setTimeout(() => {
  setStore(v => { v.a = 5555 })
}, 1000)

// observe that Projection is not updated. 


export default function App() {
  return (
    <div class="p-2">
      <div>
        Store: {store.a}  <hr />
        Projection : {storeProjection.a}  <b>&lt;---</b><hr />
        Projection(nested) : {storeProjection2.nested.a}  <hr />
      </div>
    </div>
  );
}

if (typeof document !== 'undefined') {
  render(() => <App />, document.getElementById('root')!);
}

expect rendered to be this after the store update.

Store: 5555
Projection : 5555
Projection(nested) : 5555

actual

Store: 5555
Projection : 1
Projection(nested) : 5555

Your Example Website or App

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

Steps to Reproduce the Bug or Issue

see reproduction code

Expected behavior

projected store should project the store it is returning.

Screenshots or Videos

Image

Platform

.

Additional context

worked in beta.15

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