Skip to content

2.0.0-rc.1 | refresh(store) inside an action(), does not refresh the store #3026

Description

@mizulu

Describe the bug

refresh(store) inside and action() does not refresh the store

works fine with optimistic Store

Your Example Website or App

https://s.olid.uk/id/JuDCkoHUT9WbO-KG_6sQRA

Steps to Reproduce the Bug or Issue

see reproduction

Expected behavior

it is expected that ta refresh on a store, will evaluate the store source function

Screenshots or Videos

Image

Platform

.

Additional context

import { render, ref } from '@solidjs/web';
import { createSignal, createStore, action, createOptimisticStore, refresh } from 'solid-js';

const data = {
  messages: []
}


export default function App() {
  var i = 0
  const [store, setStore] = createStore(() => {
    console.log("store eval") // expect to see this twice in the logs but only shows once for initial 
    return data
  }, { messages: [] })




  const [count, setCount] = createSignal(0);

  const act1 = action(function* act1() {

    yield new Promise(r => setTimeout(r, 1000))

    console.log("refresh(store)")
    refresh(store) // refreshing the store does not trigger the store source function 

    // This works when uncommented
    // setTimeout(()=>{
    //   refresh(store)
    // })
   

  })

  setTimeout(() => {
    act1()
    i++
    console.log("set store")
    setStore(v => v.messages.push(i))

    data.messages.push(i * 2)

  }, 2000)
  return (
    <div class="p-2">

      Store: {JSON.stringify(store.messages)}
      <hr />
   
      <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={() => setCount(count() + 1)}>
        Count: {count()}
      </button>
    </div>
  );
}


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

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