Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ignored stores serializing forked initial value #903

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/effector/__tests__/fork/serialize.test.ts
Expand Up @@ -85,6 +85,16 @@ test('serialize: ignore with fork(values)', async () => {
expect(serialize(scope)).toEqual({b: 1})
})

test('serialize: ignore with fork(values) for unchanged stores', async () => {
const $a = createStore(0, {sid: 'a', serialize: 'ignore'})

const scope = fork({
values: [[$a, 1]],
})

expect(serialize(scope)).toStrictEqual({})
})

describe('serialize: custom', () => {
test('base case', async () => {
expect.assertions(4)
Expand Down
7 changes: 7 additions & 0 deletions src/effector/fork/fork.ts
Expand Up @@ -4,6 +4,7 @@ import type {Domain, ValuesMap, HandlersMap, Scope, Store} from '../unit.h'
import {normalizeValues} from './util'
import {createScope} from './createScope'
import {forEach} from '../collection'
import {getMeta} from '../getter'

type ForkConfig = {
values?: ValuesMap
Expand Down Expand Up @@ -39,6 +40,12 @@ export function fork(
Object.assign(scope.values.sidMap, sidMap)
forEach(unitMap, (value, unit) => {
scope.values.idMap[(unit as Store<any>).stateRef.id] = value

const serialize = getMeta(unit, 'serialize')
const sid = getMeta(unit, 'sid')
if (serialize === 'ignore') {
scope.sidSerializeSettings.set(sid, {ignore: true})
}
})
scope.fromSerialize =
!Array.isArray(config.values) && !(config.values instanceof Map)
Expand Down