Compare commits

...

2 Commits

Author SHA1 Message Date
Ammar Ahmed
84141fb37a mobile: do not wrap postMessage call in a timeout 2026-08-21 09:34:22 +05:00
Ammar Ahmed
70bfb4a5d9 mobile: fix editor save performance
Add debounce on save that grows with note size, to avoid contention on the RN thread
2026-08-21 08:57:03 +05:00
2 changed files with 25 additions and 15 deletions

View File

@@ -165,7 +165,7 @@ export function useEditorController({
tabId,
noteId,
currentSessionId,
1000
20000
];
const pendingTitleIds = await pendingSaveRequests.getPendingTitleIds();
postAsyncWithTimeout(EditorEvents.title, ...params)
@@ -230,6 +230,11 @@ export function useEditorController({
clearTimeout(timers.current?.change);
}
const changeDebounce = Math.min(
1000,
Math.max(100, editor.state.doc.content.size / 100)
);
timers.current.change = setTimeout(async () => {
if (tabRef.current.session?.noteId !== noteId) {
logger(
@@ -244,7 +249,14 @@ export function useEditorController({
}
const editedAt = Date.now();
const __perfStart = performance.now();
htmlContentRef.current = editor.getHTML();
logger(
"info",
`[PERF] getHTML size=${htmlContentRef.current.length} docSize=${
editor.state.doc.content.size
} took=${(performance.now() - __perfStart).toFixed(1)}ms`
);
const params = [
{
@@ -254,7 +266,7 @@ export function useEditorController({
tabId,
noteId,
currentSessionId,
5000
20000
];
const pendingContentIds =
@@ -291,7 +303,7 @@ export function useEditorController({
});
logger("info", "Editor saving content", params[1], params[2]);
}, 100);
}, changeDebounce);
countWords(5000);
},

View File

@@ -240,18 +240,16 @@ export function post(
): string {
const id = randId(type);
if (isReactNative()) {
setTimeout(() =>
window.ReactNativeWebView.postMessage(
JSON.stringify({
type,
value: value,
sessionId: sessionId || globalThis.sessionId,
tabId,
noteId,
resolverId: id,
hasTimeout: hasTimeout
})
)
window.ReactNativeWebView.postMessage(
JSON.stringify({
type,
sessionId: sessionId || globalThis.sessionId,
tabId,
noteId,
resolverId: id,
hasTimeout: hasTimeout,
value: value
})
);
}
return id;