You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The memoed store getter pattern from the official docs throws an error (fullName is not a function). It seems the getter is immediately invoked when the store is created (i.e. before actually explicitly accessing it). At that point in time the memoed function isn't defined yet, hence the error.
To Reproduce
Provide a code snippet and steps to reproduce the behavior:
Hmm, not sure. The docs/example per se are fine. It's unexpected to me though that the getter is immediately executed by createStore and was wondering whether that's a bug... I am happy to move the issue though if that makes more sense.
It shouldn't be executing on initial creation which is why the docs are written that way. If it is executing immediately that is a Solid bug. I use this pattern in the Realworld Demo app. It worked in 1.0 and I don't believe that stuff has changed but we should look at the reproduction.
is written in the docs, and such getter will call the inner function immediately. This is a mistake, it should be:
get fullName() {
return fullName
}
to return a reference to the memoized function. Those two brackets after fullName should not be there.
Sorry, I was wrong - completely missed that this is a getter. This is a bug in createStore, since fullName is called before it's initialized.
Getters only run when accessed, in this case, fullName getter should not even evaluate given that the property wasn't accessed even before createMemo. This is a bug.
The demo is running in dev mode (_SOLID_DEV_) and since options.name hasn't been set invokes DEV.hashValue on the initial store which further down JSON.stringifies the initial store, which tries to evaluate the getter method.
That makes a lot of sense. Thank you @cynecx, that saves me some investigation. Some of the Dev mode stuff less tested in conjunction. Ok, well looks like we have a direction. I should have made a test for nesting Memos too.. I think I just disliked how it looked and hoped to do something differently at some point and just never added them. That's a mistake.
Reacted by cynecx, Alexis H. Munsayac and Markus Hsi-Yang Fritz
Activity
lxsmnsyc commentedon Sep 20, 2021
CMIIW but I think this issue should be flagged on https://github.com/solidjs/solid-docs
mhyfritz commentedon Sep 20, 2021
Hmm, not sure. The docs/example per se are fine. It's unexpected to me though that the getter is immediately executed by
createStoreand was wondering whether that's a bug... I am happy to move the issue though if that makes more sense.ryansolid commentedon Sep 20, 2021
It shouldn't be executing on initial creation which is why the docs are written that way. If it is executing immediately that is a Solid bug. I use this pattern in the Realworld Demo app. It worked in 1.0 and I don't believe that stuff has changed but we should look at the reproduction.
high1 commentedon Sep 20, 2021
@mhyfritz this is a documentation issue. Just return fullName, without calling it.
ryansolid commentedon Sep 20, 2021
What is in the docs should work. The idea is the getter is just a simple getter. So what you put in is what you get out. It shouldn't run immediately.
This is what it should be:
The get should be deferred to the property access. In so you can use it like
store.fullNameon demand. The get function shouldn't be ran immediately. https://github.com/solidjs/solid/blob/main/packages/solid/store/src/store.ts#L84high1 commentedon Sep 20, 2021
It should not, @ryansolid. There is a mistake.
is written in the docs, and such getter will call the inner function immediately. This is a mistake, it should be:
to return a reference to the memoized function. Those two brackets after fullName should not be there.
Sorry, I was wrong - completely missed that this is a getter. This is a bug in createStore, since fullName is called before it's initialized.
lxsmnsyc commentedon Sep 20, 2021
Getters only run when accessed, in this case,
fullNamegetter should not even evaluate given that the property wasn't accessed even beforecreateMemo. This is a bug.high1 commentedon Sep 20, 2021
Yep, my bad. It's a bug in createStore - happens with or without createMemo.
cynecx commentedon Sep 20, 2021
The problem is:
solid/packages/solid/store/src/store.ts
Lines 368 to 371 in 670f4f3
The demo is running in dev mode (
_SOLID_DEV_) and sinceoptions.namehasn't been set invokesDEV.hashValueon the initial store which further downJSON.stringifiesthe initial store, which tries to evaluate the getter method.ryansolid commentedon Sep 20, 2021
That makes a lot of sense. Thank you @cynecx, that saves me some investigation. Some of the Dev mode stuff less tested in conjunction. Ok, well looks like we have a direction. I should have made a test for nesting Memos too.. I think I just disliked how it looked and hoped to do something differently at some point and just never added them. That's a mistake.
fix solidjs#661 - state setter, fix solidjs#662 - hasing getters, upd…
fix solidjs#661 - state setter, fix solidjs#662 - hasing getters, upd…