#110766InlineControlContainer: initialization race condition (regression of #106371)
Description
Since #109215 (039ba0f62c, “Convert InlineControlContainer to web component”) the <typo3-formengine-container-inline> element resolves its records container once in connectedCallback():
this.recordsContainer = this.querySelector(selector`[id="${this.id}_records"]`);
The previous await DocumentService.ready() was removed with the reasoning that “connectedCallback already guarantees DOM presence”. That only holds for the element itself, not for its children. Backend modules are loaded as <script type="module" async>, so on slow or streamed responses the element can be upgraded while the parser has not yet reached the _records container. recordsContainer then stays null for the lifetime of the element.
This is exactly the case #106371 (38e558813a) fixed in 12.4/13.4/main for files-control-container.ts (“we must never assume that DOM is fully loaded in connectedCallback”). Since #109226 file references use InlineControlContainer, so that fix no longer applies to file fields.
Symptoms
Production only, intermittent, never on a local DDEV setup:
- Adding an image to a file field (e.g. Text & Media) via the element browser:
TypeError: Cannot read properties of null (reading 'insertAdjacentHTML') at createRecord() - With
appearance.useSortable = truealready on load:TypeError: Cannot read properties of null (reading 'getAttribute')inregisterEvents()
How to reproduce
Serve a FormEngine form whose HTML is flushed in two chunks with a delay between the opening <typo3-formengine-container-inline> tag and its _records child, or throttle the network in DevTools. Minimal standalone repro: a custom element defined by an async module script, queried children in connectedCallback(), HTML streamed with a 1 s pause. The child is null in 3/3 runs (headless Chrome).
Suggested fix
Restore the wait before querying children, as done in #106371:
public async connectedCallback(): Promise<void> {
await DocumentService.ready();
this.ajaxDispatcher = new AjaxDispatcher(this.objectGroup);
this.recordsContainer = <HTMLDivElement>this.querySelector(selector`[id="${this.id}_records"]`);
this.registerEvents();
}
Workaround / patch
The attached patch (typo3-backend-inline-control-container-race.patch) was created with the help of Claude (AI assistant), modeled on the approach of #106371. It applies to the compiled JavaScript of typo3/cms-backend 14.3.7 (applied via cweagans/composer-patches). Instead of an unconditional DocumentService.ready(), it defers the initialization to DOMContentLoaded only if the document is still loading and the _records container is not yet present; otherwise the behaviour is unchanged.
Verified on our production system (14.3.7): with the patch applied, the error no longer occurs.
Related: #106371, #102550, #109215, #109226
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] InlineControlContainer: initialization race condition (regression of #106371) Resolves: #110766 Releases: main