Draft Notes on Added Lines Don't Render When base_sha != start_sha
Problem
When the target branch (main) moves forward after an MR is created, base_sha (merge base) diverges from start_sha (current main HEAD). In this state:
-
Published notes (Discussions API) on added lines (
new_lineonly) render correctly✅ -
Draft notes (Draft Notes API) on added lines (
new_lineonly) do not render on the diff❌
This issue doesn't happen when the main has not moved forward (base_sha == start_sha)
How to reproduce
This MR sets up the test case viktomas/test-project!37
Setup:
- Branch
tv/diff-line-testaddssum()andaverage()at end ofsrc/utils.ts - Main gets 6 new header lines, shifting all line numbers by +6
-
diff_refs:base_sha=eaa82a4≠start_sha=a377257
Test results on viktomas/test-project!37 (diffs)
Reproducer: curl Commands
Get diff_refs from the MR first:
curl -s -H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
"https://gitlab.com/api/v4/projects/viktomas%2Ftest-project/merge_requests/37" \
| jq '.diff_refs'
# {
# "base_sha": "eaa82a43a06204f6f9b6092950ceba92720773f0",
# "start_sha": "a377257a71a83665cd2e5ae5a7e42b97526b6548",
# "head_sha": "dc5ec65e783268ba590bc08245e1bd6ae3b989a6"
# }
curl -s -X POST \
-H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"body": "This renders correctly on the added line",
"position": {
"position_type": "text",
"base_sha": "eaa82a43a06204f6f9b6092950ceba92720773f0",
"head_sha": "dc5ec65e783268ba590bc08245e1bd6ae3b989a6",
"start_sha": "a377257a71a83665cd2e5ae5a7e42b97526b6548",
"new_path": "src/utils.ts",
"old_path": "src/utils.ts",
"new_line": 48
}
}' \
"https://gitlab.com/api/v4/projects/viktomas%2Ftest-project/merge_requests/37/discussions"
This shows on the diff
curl -s -X POST \
-H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"note": "This is invisible on the diff despite valid line_code",
"position": {
"position_type": "text",
"base_sha": "eaa82a43a06204f6f9b6092950ceba92720773f0",
"head_sha": "dc5ec65e783268ba590bc08245e1bd6ae3b989a6",
"start_sha": "a377257a71a83665cd2e5ae5a7e42b97526b6548",
"new_path": "src/utils.ts",
"old_path": "src/utils.ts",
"new_line": 48
}
}' \
"https://gitlab.com/api/v4/projects/viktomas%2Ftest-project/merge_requests/37/draft_notes"
shows in the list of draft notes, but not on the diff
The only difference is the endpoint (discussions vs draft_notes) and field name (body vs note). The position is identical. The prerequisite is base_sha != start_sha (target branch moved after MR creation).

