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

array.shift/pop not working with array length === 1 #1105

Closed
tarno0se opened this issue Dec 10, 2018 · 9 comments
Closed

array.shift/pop not working with array length === 1 #1105

tarno0se opened this issue Dec 10, 2018 · 9 comments
Assignees
Labels
bug Confirmed bug

Comments

@tarno0se
Copy link

Bug report

Sandbox link or minimal reproduction code
https://codesandbox.io/s/0mn56vlkw0?expanddevtools=1&hidenavigation=1&module=%2Fsrc%2Findex.ts&view=editor

Describe the expected behavior
1 2

Describe the observed behavior
1 ScalarNode$$1 {subpathAtom: Atom$$1, state: 4, hookSubscribers: Object, environment: undefined, subpath: ""…}

@k-g-a
Copy link
Member

k-g-a commented Dec 10, 2018

Thanks! It's definitely a bug. Introduced in 3.2.2. Used to throw setParent is not supposed to be called on scalar nodes at 3.2.1 and lower.

@k-g-a k-g-a added the bug Confirmed bug label Dec 10, 2018
@xaviergonz
Copy link
Contributor

shouldn't it just return the other pushed item?

@k-g-a
Copy link
Member

k-g-a commented Dec 11, 2018

It should return .storedValue (2 in that case) instead of whole ScalarNode object. Will look into this today.

@k-g-a k-g-a self-assigned this Dec 11, 2018
@k-g-a
Copy link
Member

k-g-a commented Dec 11, 2018

At first glance it seems like a mobx bug:
https://github.com/mobxjs/mobx/blob/04dc6200536bb4588ea0ac2af377e426f9955fb0/src/types/observablearray.ts#L157

dehanceValues(values: any[]): any[] {
        // this.value.lenght > 0 check fails
        if (this.dehancer !== undefined && this.values.length > 0)
            return values.map(this.dehancer) as any
        return values
    }

It seems like we should check values.length > 0, not this.values.length. Because this.values is fairly empty at this point: spliceItemsIntoValues() modified it couple of rows before.
@mweststrate , could you confirm? Can make a PR.

@k-g-a
Copy link
Member

k-g-a commented Dec 11, 2018

Made a PR for mobx.
Not sure if we have to do something at MST.
We could upgrade peerDependencies or write a remark at FAQ about this issue?

@xaviergonz
Copy link
Contributor

I think a peer dep upgrade is better, but that's just my personal opinion.

@mweststrate
Copy link
Member

mweststrate commented Dec 11, 2018 via email

@k-g-a
Copy link
Member

k-g-a commented Dec 13, 2018

To fix this issue, please upgrade your mobx version to 4.8.0/5.8.0.

@k-g-a
Copy link
Member

k-g-a commented Dec 13, 2018

For new users will be fixed by #1111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants