lukeed / lukeed/dset

Strange bug using dset with mobx

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

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
783
Forks
29
PR merge metrics
No merged PRs in 30d

Description

I noticed that there is a weird bug when using `dset` with `mobx`:
```
dset(data, "a.b.c", 1)
```

If `data` is an mobx observable (a deep and proxied one), `dset` will set only the first key `a` with an empty object.
The result will be:
```
{ a: {} }
```
instead of
```
{ a: { b: { c: 1 } } }
```

It happens only when using *deep* and *proxy* options in mobx (that are the default options).

Struggling with it, I found out that it is the multiple assignment used in `dset` function that breaks it.
It can be fixed splitting the multiple assignment into 2 different lines.

I created a sandbox that shows everything I state here (fix included):
https://codesandbox.io/s/dset-mobx-issue-x99gw

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.

Research direction

Start with the dset function and reproduce the deep, proxied MobX case using the linked CodeSandbox. Compare the current result with the expected nested object and verify the behavior after the reported assignment change; the work is done when the nested path is written correctly without breaking ordinary dset usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.