question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(reducers): updates to arrays inside documents don't work as expected

See original GitHub issue

Do you want to request a feature or report a bug?
bug

What is the current behavior? If you store an array inside a firestore document (e.g. { content: ['an', 'array'] }) and update that document such that the array is shorter ({ content: ['single'] }), the update action that fires merges the arrays and doesn’t delete the extra elements ({ content: ['single', 'array'] }).

Note that { content: ['single'] } is what is in the firestore database at this stage.

What is the expected behavior? For the array to be pruned

Which versions of dependencies, and which browser are affected by this issue? Did this work in previous versions or setups? Definitely exists in 0.5.8, unclear if it worked previously

Steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar. See pull request and the test attached.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
GuillemotFcommented, Sep 28, 2018

I have a similar behaviour with objects in a document (instead of an array) when removing a property.

Example :

const documentUpdate = {};
documentUpdate['someObject.someProperty'] =  firestore.FieldValue.delete();
firestore.update(
      {
        collection: 'test',
        doc: 'someId',
      },
      documentUpdate,
);

Will correctly update data state in redux but not the ordered one.

Edit : Your PR also fixes this issue

2reactions
YuvalKleincommented, Feb 19, 2019

Yeesss!! working! thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reducer: Updating an array inside an array - Stack Overflow
I'm getting an error: "Uncaught TypeError: Invalid attempt to spread non-iterable instance" on the line "const arr = [...state.tabs[index].
Read more >
Writing Reducers with Immer | Redux Toolkit - JS.ORG
Reducers can only make copies of the original values, and then they can mutate the copies. We already saw that we can write...
Read more >
Array.prototype.reduce() - JavaScript - MDN Web Docs
The reduce() method executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value ...
Read more >
Docs • Svelte
Svelte's <script> blocks are run only when the component is created, so assignments within a <script> block are not automatically run again when...
Read more >
How to Add to an Array in React State using Hooks
The .push() function will not work, but the .concat() function can update state in ... We call it inside a function component to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found