← Back to Dashboard
Verified Production Fix

[gitlab-org/gitlab] discussions store: updateNote uses deep merge where splice used full replacement

GL-gitlab-org/gitlab#592641 • Mar 07, 2026

### ROOT CAUSE The issue arises because the `UPDATE_NOTE` mutation uses `lodash.merge`, which performs a deep merge, preserving existing properties that might no longer be present in the server's response. This can lead to stale data if the API response structure changes. The original `splice` method replaced the entire note object, correctly removing missing properties but breaking reactivity. ### CODE FIX To address the issue while maintaining reactivity and ensuring that missing properties are removed, we'll switch to using `Object.assign` for top-level properties. This approach updates the existing object's properties without replacing the entire object, preserving reactivity. Additionally, we'll ensure that any properties not present in the new data are removed. **Step-by-Step Explanation:** 1. **Use `Object.assign`:** Replace `lodash.merge` with `Object.assign` to update the existing note's properties at the top level. This maintains the same object reference, preserving reactivity. 2. **Remove Missing Properties:** After updating, iterate over the existing properties and delete any that are not present in the new data to ensure missing properties are removed. **Modified Code:**

// In mutations.js, replace the updateNote method
export const updateNote = (state, { note, noteId }) => {
  const existingNote = state.notes[noteId];
  // Update existingNote with new data using Object.assign
  Object.assign(existingNote, note);
  // Remove any properties not present in the new note data
  const keysToKeep = Object.keys(note);
  Object.keys(existingNote).forEach(key => {
    if (!keysToKeep.includes(key)) {
      delete existingNote[key];
    }
  });
};


This solution ensures that the note's properties are updated correctly, reactivity is maintained, and any missing properties are removed, addressing the root cause effectively.

Deploy with DigitalOcean

Use this fix in production instantly. Claim your $200 developer credit.

Get Started →