(open dev tools to observe network requests in the first tab)
in the first tab, navigate to a different page, and press the back button
Observe error in trpc/comment.handleChangesets API request:
Invalid `prisma.comment.createMany()` invocation:
Unique constraint failed on the fields: (`id`)
Expected behavior
No error, first tab should not even attempt to make a comment.handleChangesets request.
Additional context
No response
Technical ideas
Front-end Zustand stores are saving diffs when changes are made. Changes are made when a page is loaded, but the store prevents saving by avoiding doing so if the topic.id changes. If the topic.id does not change, we may create an unintended additional API request to set data.
We should not be relying on topic.id to prevent unintended saves. We should add a mechanism to the store like undo/redo has (for pausing undo/redo tracking) to pause store syncing (we'd pause before loading data and resume after it's loaded).
Describe the bug
See reproduction
To Reproduce
Observe error in
trpc/comment.handleChangesets
API request:Expected behavior
No error, first tab should not even attempt to make a
comment.handleChangesets
request.Additional context
No response
Technical ideas
Front-end Zustand stores are saving diffs when changes are made. Changes are made when a page is loaded, but the store prevents saving by avoiding doing so if the topic.id changes. If the topic.id does not change, we may create an unintended additional API request to set data.
We should not be relying on topic.id to prevent unintended saves. We should add a mechanism to the store like undo/redo has (for pausing undo/redo tracking) to pause store syncing (we'd pause before loading data and resume after it's loaded).