Skip to content

Commit aa723de

Browse files
silverwindGiteaBot
andauthored
Don't autosize textarea in diff view (#26233)
Resizing the comment editor can be a very expensive operation because it triggers page reflows, which on large PRs can take upwards of seconds to complete. Disable this mechanism on the diff page only where we know that the page can get large. Fixes #26201 for the textarea editor. I don't think this can be fixed for EasyMDE because as far as I can tell, it exposes no option to disable this resizing. --------- Co-authored-by: Giteabot <[email protected]>
1 parent 4244ce0 commit aa723de

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

templates/repo/diff/comment_form.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"TextareaName" "content"
1818
"TextareaPlaceholder" ($.locale.Tr "repo.diff.comment.placeholder")
1919
"DropzoneParentContainer" "form"
20+
"DisableAutosize" "true"
2021
)}}
2122

2223
<div class="field footer gt-mx-3">

templates/shared/combomarkdowneditor.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Template Attributes:
1010
* TextareaPlaceholder: placeholder attribute for the textarea
1111
* TextareaAriaLabel: aria-label attribute for the textarea
1212
* DropzoneParentContainer: container for file upload (leave it empty if no upload)
13+
* DisableAutosize: whether to disable automatic height resizing
1314
*/}}
1415
<div {{if .ContainerId}}id="{{.ContainerId}}"{{end}} class="combo-markdown-editor {{.ContainerClasses}}" data-dropzone-parent-container="{{.DropzoneParentContainer}}">
1516
{{if .MarkdownPreviewUrl}}
@@ -45,7 +46,7 @@ Template Attributes:
4546
</div>
4647
</markdown-toolbar>
4748
<text-expander keys=": @" suffix="">
48-
<textarea class="markdown-text-editor js-quick-submit"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}>{{.TextareaContent}}</textarea>
49+
<textarea class="markdown-text-editor js-quick-submit"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}{{if .DisableAutosize}} data-disable-autosize="{{.DisableAutosize}}"{{end}}>{{.TextareaContent}}</textarea>
4950
</text-expander>
5051
<script>
5152
if (localStorage?.getItem('markdown-editor-monospace') === 'true') {

web_src/js/features/comp/ComboMarkdownEditor.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ class ComboMarkdownEditor {
6969
this.textarea.id = `_combo_markdown_editor_${String(elementIdCounter++)}`;
7070
this.textarea.addEventListener('input', (e) => this.options?.onContentChanged?.(this, e));
7171
this.applyEditorHeights(this.textarea, this.options.editorHeights);
72-
this.textareaAutosize = autosize(this.textarea, {viewportMarginBottom: 130});
72+
73+
if (this.textarea.getAttribute('data-disable-autosize') !== 'true') {
74+
this.textareaAutosize = autosize(this.textarea, {viewportMarginBottom: 130});
75+
}
7376

7477
this.textareaMarkdownToolbar = this.container.querySelector('markdown-toolbar');
7578
this.textareaMarkdownToolbar.setAttribute('for', this.textarea.id);
@@ -247,7 +250,7 @@ class ComboMarkdownEditor {
247250
} else {
248251
this.textarea.value = v;
249252
}
250-
this.textareaAutosize.resizeToFit();
253+
this.textareaAutosize?.resizeToFit();
251254
}
252255

253256
focus() {

0 commit comments

Comments
 (0)