From 776e1cee7b683da858dfa52c7f1cb7a9d5dda75b Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 3 Oct 2024 15:55:35 +0200 Subject: [PATCH] Fix bug with dictation on iOS 18+ Dictation on iOS does not trigger composition events (https://bugs.webkit.org/show_bug.cgi?id=261764). Instead, it triggers `beforeinput` events with `insertText`. During the dictation phase, it keeps the range anchored to the cursor, and iOS may modify past text as new text adds context. Once dictation is stopped, it starts sending `insertText` events with word fragments. When a past fragment is altered, iOS sends a `beforeinput` event where `inputType` is null. In this case, perform a synchronous render operation to set the editor to the correct state. Otherwise, scheduled render requests can process invalid ranges and mess with the editor contents. --- src/trix/controllers/level_2_input_controller.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/trix/controllers/level_2_input_controller.js b/src/trix/controllers/level_2_input_controller.js index dc4bf7dc9..65b302157 100644 --- a/src/trix/controllers/level_2_input_controller.js +++ b/src/trix/controllers/level_2_input_controller.js @@ -73,6 +73,11 @@ export default class Level2InputController extends InputController { beforeinput(event) { const handler = this.constructor.inputTypes[event.inputType] + // Handles bug with Siri dictation on iOS 18+. + if (!event.inputType) { + this.render() + } + if (handler) { this.withEvent(event, handler) this.scheduleRender()