Typing in a TextEditorField gets progressively slower on a form holding several Trix editors
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 70/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, php, symfony
- Ambito
- frontend, performance
Direzione di ricerca
Inizia da assets/js/field-text-editor.js, in particolare dall’handler trix-before-initialize, #processRequiredAttribute() e #enableFormChangesDetection(); quindi confronta il suo utilizzo di DirtyForm con assets/js/form.js. Riproduci il problema in un form con diversi editor Trix e usa lo snippet di misurazione dei tempi nella console. Il lavoro è completato quando la digitazione non diventa più progressivamente più lenta e vengono evitati i listener ridondanti a livello di documento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Typing in a TextEditorField gets progressively slower on a form holding several Trix editors
Symptom
On an edit form holding many Trix editors, typing lags, and the lag grows with every character typed. On one of our pages (31 editors, ~400 form fields), a single character insertion measured, five times in a row from a fresh page load:
142 ms → 228 ms → 294 ms → 349 ms → 398 ms
It never comes back down; only a page reload resets it.
Cause
assets/js/field-text-editor.js builds one TextEditorField per editor on the page:
// field-text-editor.js:11
document.addEventListener('trix-before-initialize', () => {
new TextEditorField();
});
trix-before-initialize fires once per <trix-editor> element, so a form with N editors ends up with N instances. Each instance adds two more document-level trix-change listeners:
#processRequiredAttribute()(line 67) →#markInvalidFormFields(), which re-scans.ea-edit-formwithquerySelectorAll('input,select,textarea')and callssetCustomValidity()on every field.#enableFormChangesDetection()(line 75) →new DirtyForm(form).
DirtyForm's constructor walks the whole form.elements collection and attaches a new change + input listener to each field. Those listeners are never removed, and the bound callbacks are new function objects each time, so nothing is deduplicated.
So one keystroke costs N_editors × N_fields, and it also leaves N_editors × N_fields × 2 extra listeners behind, which the next keystroke pays for again. Hence the linear growth above.
Repro
- Any CRUD edit page with, say, 20+
TextEditorFieldinstances (ours are nested inside aCollectionField). - Open the console and run this a few times in a row:
const e = document.querySelector('trix-editor');
const t = performance.now(); e.editor.insertString('a'); console.log(performance.now() - t);
The number rises on every call.
Suggested fix
Two independent points:
- Build
TextEditorFieldonce.#processRequiredAttribute()and#handleFormSubmission()already query the whole document / the submitted form, so a single instance covers every editor. A guard on the listener would do:
let textEditorField = null;
document.addEventListener('trix-before-initialize', () => {
textEditorField ??= new TextEditorField();
});
(#processRequiredAttribute() would then need to run again for editors added later — an ea.collection.item-added listener, or re-running just the per-element part on trix-before-initialize.)
- Drop
#enableFormChangesDetection()entirely.assets/js/form.jsalready instantiatesDirtyFormonce onDOMContentLoadedfor.ea-new-form/.ea-edit-form, andDirtyFormhandles<trix-editor>natively (it collectsform.querySelectorAll('trix-editor')and bindstrix-changeon them). The rebuild here looks redundant — and because it re-snapshotsinitialValueson every keystroke, it arguably weakens the very detection it is meant to provide.
Point 2 alone removes the unbounded growth; point 1 removes the × N_editors factor.
Workaround
For anyone hitting this before a fix lands: keeping trix-change inside the editor it came from (stopPropagation() on the <trix-editor> element, which still lets form.js's own DirtyForm see it — it listens on that element, not on the document) brought that same measurement from 142 ms down to ~15 ms. It does mean taking over #markInvalidFormFields() for those fields, which is two lines given data-ea-trix-is-required is already on the textarea.
Versions
- easycorp/easyadmin-bundle 5.5.0
- Symfony 8.x, PHP 8.4
- Chrome
Investigation and write-up done with Claude Code, on a real project of mine. The timings above are actual measurements I ran in my own browser console, not estimates.
- Lingua principale
- PHP
- Stelle
- 4.3k
- Fork
- 1.1k
- Merge medio
- 2g 9h
- PR unite (30g)
- 52
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di EasyCorp/EasyAdminBundle
-
bug design
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
EasyCorp/EasyAdminBundle#7958 ·
I maintainer di solito rispondono entro 2 giorni
-
design feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
EasyCorp/EasyAdminBundle#7930 ·
I maintainer di solito rispondono entro 2 giorni
-
design
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 88/100
EasyCorp/EasyAdminBundle#7879 ·
I maintainer di solito rispondono entro 2 giorni
-
design
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
EasyCorp/EasyAdminBundle#7875 ·
I maintainer di solito rispondono entro 2 giorni
-
#[AdminRoute]: the requirements of an action silently replace the ones of the classForse già presa @anthonyhacart l’ha presa 2 giorni fa. Apertafeature
Difficoltà 3/5 Mezza giornata Idoneità per principianti 30/100
EasyCorp/EasyAdminBundle#7956 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di EasyCorp/EasyAdminBundle
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
taskforcesh/bullmq#5238 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itForse già presa @bfs2021 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Automattic/jetpack#55517 ·
I maintainer di solito rispondono entro 1 giorno
-
Address edit modal: what the customer types before the fields load is reset to the saved valueApertaMajor
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
PrestaShop/ps_onepagecheckout#245 ·
I maintainer di solito rispondono entro 1 giorno
-
wpvc
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
10up/ElasticPress#4420 ·
I maintainer di solito rispondono entro 1 giorno