From 96e32f57e5aef143eca142d5520b6016775af501 Mon Sep 17 00:00:00 2001 From: Colin Caine Date: Wed, 7 Mar 2018 02:09:41 +0000 Subject: [PATCH] Fix #311 - Don't write to browser.storage so often Turns out writing to browser.storage is expensive because state.ts and config.ts both listen for it in every tab. I'd vaguely assumed that Firefox would run other tabs as low priority tasks and that this would not be an issue, but it doesn't. I also wrote the code in a rush, and while I mused that this potential risk exists I didn't document it or explore it. Retrospective: Content switches are expensive - think before you do anything that may wake many processes and don't make wild assumptions about how Firefox handles multiprocessing. --- package-lock.json | 2 +- src/controller.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 25671b9f..883d7ee9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9513,7 +9513,7 @@ } }, "web-ext-types": { - "version": "github:kelseasy/web-ext-types#417d6ddcd76d8a05d7e2222aec3544e01637785b", + "version": "github:kelseasy/web-ext-types#5fa885198a9d43a35dfd0afec64c5ff89338f8a0", "dev": true }, "webidl-conversions": { diff --git a/src/controller.ts b/src/controller.ts index 0887a92b..54b64f0e 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -35,10 +35,14 @@ function *ParserController () { let keyevent: MsgSafeKeyboardEvent = yield let keypress = keyevent.key - // TODO: think about if this is robust + // This code was sort of the cause of the most serious bug in Tridactyl + // to date (March 2018). + // https://github.com/cmcaine/tridactyl/issues/311 if (state.mode != "ignore" && state.mode != "hint" && state.mode != "input") { if (isTextEditable(keyevent.target)) { - state.mode = "insert" + if (state.mode !== 'insert') { + state.mode = "insert" + } } else if (state.mode === 'insert') { state.mode = "normal" }