Menu

1 / 4

My WKWebView editor froze on typing, and the cause was the user’s text replacements

DEV Community: swift·Apps by Mo·about 7 hours ago
#5i9gHWKm
#devtoswift#devto#dev#editor#harness
Long article (486 words) — no AI summary yet.
Reading 0:00
15s threshold

A text editor in one of my Mac apps froze while people typed. Not a crash, not a spinner: each key landed late, and on an older Mac the window simply stopped answering for a moment. The editor is a contenteditable page inside a WKWebView, which is a very ordinary setup, so I expected a slow script of my own. It was not mine at all.

Measure before guessing

I built a small harness: a real WKWebView, keys sent with insertText and real NSEvent s, and sample running against both processes while it typed. Two things showed up right away.

First, on every typed character WebKit's web process asks the app's main thread to check the paragraph's text. That is a synchronous call, so the web view waits for the answer before the next key.

Second, almost all of that time was not spelling. It was NSSpellChecker building its dictionary of the user's text replacements, the shortcuts you set in System Settings > Keyboard > Text Replacements.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.