diff --git a/app/views/projects/blob/diff.html.haml b/app/views/projects/blob/diff.html.haml
index 3b1a2e54ec2031282a2ac80c4dd939e58cf1239f..d1f7f65bf53a3d56717a3673cf07ad8db4ebb5e0 100644
--- a/app/views/projects/blob/diff.html.haml
+++ b/app/views/projects/blob/diff.html.haml
@@ -25,6 +25,6 @@
           = link_to raw(line_new), "##{line_new}"
         = line_content
 
-  - if @form.unfold? && @form.bottom? && @form.to < @blob.loc
+  - if @form.unfold? && @form.bottom? && @form.to < @blob.lines.size
     %tr.line_holder{ id: @form.to, class: line_class }
       = diff_match_line @form.to - @form.offset, @form.to, text: @match_line, view: diff_view, bottom: true
diff --git a/app/views/projects/diffs/_content.html.haml b/app/views/projects/diffs/_content.html.haml
index b87b79b170ebd76f0224c5c9f7213599d9635ac8..5c38b5ad9c0444ebb3338537e03241491120e46b 100644
--- a/app/views/projects/diffs/_content.html.haml
+++ b/app/views/projects/diffs/_content.html.haml
@@ -15,10 +15,13 @@
         %a.click-to-expand
           Click to expand it.
     - elsif diff_file.diff_lines.length > 0
+      - total_lines = 0
+      - if blob.lines.any?
+        - total_lines = blob.lines.last.chomp == '' ? blob.lines.size - 1 : blob.lines.size
       - if diff_view == :parallel
-        = render "projects/diffs/parallel_view", diff_file: diff_file, project: project, blob: blob
+        = render "projects/diffs/parallel_view", diff_file: diff_file, total_lines: total_lines
       - else
-        = render "projects/diffs/text_file", diff_file: diff_file
+        = render "projects/diffs/text_file", diff_file: diff_file, total_lines: total_lines
     - else
       - if diff_file.mode_changed?
         .nothing-here-block File mode changed
diff --git a/app/views/projects/diffs/_parallel_view.html.haml b/app/views/projects/diffs/_parallel_view.html.haml
index 074f1f634aed8b9544abe5c52aa44a714d39e884..997bf0fc5607c11b03e952fb5dc2cf68ab0f2635 100644
--- a/app/views/projects/diffs/_parallel_view.html.haml
+++ b/app/views/projects/diffs/_parallel_view.html.haml
@@ -43,7 +43,8 @@
         - discussion_left, discussion_right = parallel_diff_discussions(left, right, diff_file)
         - if discussion_left || discussion_right
           = render "discussions/parallel_diff_discussion", discussion_left: discussion_left, discussion_right: discussion_right
-    - if !diff_file.new_file && diff_file.diff_lines.any?
+    - if !diff_file.new_file && !diff_file.deleted_file && diff_file.diff_lines.any?
       - last_line = diff_file.diff_lines.last
-      %tr.line_holder.parallel
-        = diff_match_line last_line.old_pos, last_line.new_pos, bottom: true, view: :parallel
+      - if last_line.new_pos < total_lines
+        %tr.line_holder.parallel
+          = diff_match_line last_line.old_pos, last_line.new_pos, bottom: true, view: :parallel
diff --git a/app/views/projects/diffs/_text_file.html.haml b/app/views/projects/diffs/_text_file.html.haml
index 2eea1db169a550e74553100e3255d4683fb54002..ebd1a914ee7b27d953f164d64bed46f866442c1b 100644
--- a/app/views/projects/diffs/_text_file.html.haml
+++ b/app/views/projects/diffs/_text_file.html.haml
@@ -10,7 +10,8 @@
     as: :line,
     locals: { diff_file: diff_file, discussions: discussions }
 
-  - if !diff_file.new_file && diff_file.highlighted_diff_lines.any?
+  - if !diff_file.new_file && !diff_file.deleted_file && diff_file.highlighted_diff_lines.any?
     - last_line = diff_file.highlighted_diff_lines.last
-    %tr.line_holder
-      = diff_match_line last_line.old_pos, last_line.new_pos, bottom: true
+    - if last_line.new_pos < total_lines
+      %tr.line_holder
+        = diff_match_line last_line.old_pos, last_line.new_pos, bottom: true
diff --git a/changelogs/unreleased/26824-diff-unfold-link-is-still-visible-when-there-are-no-lines-to-unfold.yml b/changelogs/unreleased/26824-diff-unfold-link-is-still-visible-when-there-are-no-lines-to-unfold.yml
new file mode 100644
index 0000000000000000000000000000000000000000..182a9ae126b5589c8d0b243a5913a350632c04bd
--- /dev/null
+++ b/changelogs/unreleased/26824-diff-unfold-link-is-still-visible-when-there-are-no-lines-to-unfold.yml
@@ -0,0 +1,5 @@
+---
+title: prevent diff unfolding link from appearing when there are no more lines to
+  show
+merge_request: 8761
+author: