summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/store/utils.js
diff options
context:
space:
mode:
authorSam Bigelow <sbigelow@gitlab.com>2018-12-17 20:25:41 -0500
committerSam Bigelow <sbigelow@gitlab.com>2018-12-17 20:25:41 -0500
commit9c18798275d455c78ebdac2f1ed6d25112c558fa (patch)
tree09ce9951bee850e03229419b1d9d551a35bfc5d8 /app/assets/javascripts/diffs/store/utils.js
parent8b4602041cf2c4a8738a4796d78720017249249f (diff)
downloadgitlab-ce-9c18798275d455c78ebdac2f1ed6d25112c558fa.tar.gz
Utilize :key to minimize extra rerenders
The diff notes automatically focus on mount, and when using the index (as opposed to line_code) for the v-bind:key, the comment form gets unnecessarily remounted, and therefore refocused.
Diffstat (limited to 'app/assets/javascripts/diffs/store/utils.js')
-rw-r--r--app/assets/javascripts/diffs/store/utils.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/assets/javascripts/diffs/store/utils.js b/app/assets/javascripts/diffs/store/utils.js
index cbaa0e26395..2fe20551642 100644
--- a/app/assets/javascripts/diffs/store/utils.js
+++ b/app/assets/javascripts/diffs/store/utils.js
@@ -196,6 +196,15 @@ export function trimFirstCharOfLineContent(line = {}) {
return parsedLine;
}
+function getLineCode({ left, right }, index) {
+ if (left && left.line_code) {
+ return left.line_code;
+ } else if (right && right.line_code) {
+ return right.line_code;
+ }
+ return index;
+}
+
// This prepares and optimizes the incoming diff data from the server
// by setting up incremental rendering and removing unneeded data
export function prepareDiffData(diffData) {
@@ -208,6 +217,8 @@ export function prepareDiffData(diffData) {
const linesLength = file.parallel_diff_lines.length;
for (let u = 0; u < linesLength; u += 1) {
const line = file.parallel_diff_lines[u];
+
+ line.line_code = getLineCode(line, u);
if (line.left) {
line.left = trimFirstCharOfLineContent(line.left);
line.left.hasForm = false;