StepanS
Convex Community4mo ago
1 reply
Stepan

Updating one list item updates the entire list

This is a basic example of convex todo logic:

export const getAll = query({
  handler: async (ctx) => {
    return await ctx.db.query("todos").collect();
  },
});

export const create = mutation({
  args: {
    text: v.string(),
  },
  handler: async (ctx, args) => {
    const newTodoId = await ctx.db.insert("todos", {
      text: args.text,
    });
    return await ctx.db.get(newTodoId);
  },
});

When the "create" mutation is called, convex sends the client a Transition containing the entire todo list, including those that haven't been updated.

{
  "type": "Transition",
  "startVersion": {
    "querySet": 1,
    "identity": 0,
    "ts": "H9zkzpy2Zhg="
  },
  "endVersion": {
    "querySet": 1,
    "identity": 0,
    "ts": "a4S3sMi3Zhg="
  },
  "modifications": [
    {
      "type": "QueryUpdated",
      "queryId": 0,
      "value": [
        {
          "_creationTime": 1758293489109.8918,
          "_id": "j578a0636y8wcm4akgvzzv4wjd7qwjd9",
          "completed": false,
          "text": "data2"
        },
        {
          "_creationTime": 1758294777103.2942,
          "_id": "j575sseg4820aa551czakekzxs7qxkqd",
          "completed": false,
          "text": "data1"
        }
      ],
      "logLines": [],
      "journal": null
    }
  ],
  "clientClockSkew": 1090,
  "serverTs": 1758294777146437000
}

I see this problem in the official example - https://github.com/get-convex/convex-demos/tree/main/pagination

Is this normal and can it be avoided, and if so, what are the recommended practices?
Was this page helpful?