Unexpected recalculations of derived stores

Open
#37 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
next.js, typescript
Domain
frontend

Research direction

Start by reproducing the navigation sequence in the playground-app: hydrate a $server store through EffectorNext, derive a value with map() or combine(), then navigate to a page without $server data. Trace when the derived store recalculates compared with sample() and useStoreMap(); done means confirming whether the extra recalculations are expected or preventing them when the upstream value has not changed.

Written by the indexing model from the issue text.

Description

In our nextjs app we get some data on a server and then hydrate it on client via EffectorNext component. Say we have $server store which serializes and sends data to the client. I noticed that if i have some derived store (say, $derived) based on this value via .map() or combine() utilitiy on each navigation i get multiple recalculations of this derived store despite the fact that the docs state that it should only recalculate when upstream store changes. Recalculations are called with the latest value of $server store.

Here are the steps to reproduce:

  1. provide some value via $server store. Derived store calculates correctly
  2. navigate to some other page with no $server value provided. For some reason derived store recalculates.

If I use sample() everything is ok because this derived value gets serialized as well. useStoreMap works well too but with this approach i can't access this derived value in stores.

I reproduced this in playground-app in which there are not so many recalculations but in my production app i get 500+ calls on each not shallow page transition.

Am i doing something wrong and this is expected behavior? I expect combine to not be called at all.

Dominant language
TypeScript
Stars
61
Forks
7
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from effector/next

All issues in effector/next

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.