Prerequisites
Describe the issue
Let's say we pass hard-coded <FileDiff selectedLines={null} ... />. Then we select lines (possibly using the gutter + utility). After the selection finishes, it stays in place, even if we keep passing selectedLines={null}.
Now, the selection stays in place until the component re-renders for any other reason (some other state changing), at that point the selection is cleared.
I believe the issue is that here
|
useIsometricEffect(() => { |
|
const { current: instance } = instanceRef; |
|
if (instance == null) return; |
|
const newOptions = mergeFileDiffOptions(options, hasGutterRenderUtility); |
|
const forceRender = !areOptionsEqual(instance.options, newOptions); |
|
instance.setOptions(newOptions); |
|
void instance.render({ |
|
forceRender, |
|
fileDiff, |
|
oldFile, |
|
newFile, |
|
lineAnnotations, |
|
}); |
|
if (selectedLines !== undefined) { |
|
instance.setSelectedLines(selectedLines); |
|
} |
|
}); |
instance.setSelectedLines is called on ever re-render. However, the selection even by itself does not cause a re-render. That also explains why a later re-render does clear the selection.
It probably makes sense to keep the selection if no selectedLines prop is passed at all, similar to uncontrolled React inputs. However, when selectedLines is passed, I would expect it to be the source of truth, similar to controlled React inputs.
Reproduction
As described above.
What browser(s) are you seeing the problem on?
No response
What version of @pierre/diffs are you using?
1.1.4
Prerequisites
Describe the issue
Let's say we pass hard-coded
<FileDiff selectedLines={null} ... />. Then we select lines (possibly using the gutter+utility). After the selection finishes, it stays in place, even if we keep passingselectedLines={null}.Now, the selection stays in place until the component re-renders for any other reason (some other state changing), at that point the selection is cleared.
I believe the issue is that here
pierre/packages/diffs/src/react/utils/useFileDiffInstance.ts
Lines 104 to 120 in d7db28e
instance.setSelectedLinesis called on ever re-render. However, the selection even by itself does not cause a re-render. That also explains why a later re-render does clear the selection.It probably makes sense to keep the selection if no
selectedLinesprop is passed at all, similar to uncontrolled React inputs. However, whenselectedLinesis passed, I would expect it to be the source of truth, similar to controlled React inputs.Reproduction
As described above.
What browser(s) are you seeing the problem on?
No response
What version of @pierre/diffs are you using?
1.1.4