From efda62a6ac2db0d19702d3ca4ecb1cd67582a021 Mon Sep 17 00:00:00 2001 From: Logan Yang Date: Tue, 24 Feb 2026 13:01:51 -0800 Subject: [PATCH] fix: replace Node.js Buffer with cross-platform TextEncoder for mobile indexing (#2216) Buffer.byteLength is unavailable on Obsidian mobile (Android/iOS WebView), causing indexing to fail with "Buffer is not defined". Use the existing MemoryManager.getByteSize() helper which uses TextEncoder instead. Co-authored-by: Claude Opus 4.6 --- src/search/v3/chunks.ts | 3 ++- src/search/v3/engines/FullTextEngine.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/search/v3/chunks.ts b/src/search/v3/chunks.ts index 2a104ddd..7748b3fa 100644 --- a/src/search/v3/chunks.ts +++ b/src/search/v3/chunks.ts @@ -2,6 +2,7 @@ import { logInfo, logWarn } from "@/logger"; import { CHUNK_SIZE } from "@/constants"; import { App, TFile } from "obsidian"; import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters"; +import { MemoryManager } from "./utils/MemoryManager"; /** * Chunk interface for unified search system @@ -558,7 +559,7 @@ export class ChunkManager { */ private calculateChunkBytes(chunks: Chunk[]): number { return chunks.reduce((total, chunk) => { - return total + Buffer.byteLength(chunk.content, "utf8"); + return total + MemoryManager.getByteSize(chunk.content); }, 0); } diff --git a/src/search/v3/engines/FullTextEngine.ts b/src/search/v3/engines/FullTextEngine.ts index 21ac784c..e6a274a5 100644 --- a/src/search/v3/engines/FullTextEngine.ts +++ b/src/search/v3/engines/FullTextEngine.ts @@ -179,7 +179,7 @@ export class FullTextEngine { for (let i = 0; i < chunks.length; i++) { const chunk = chunks[i]; - const contentSize = Buffer.byteLength(chunk.content, "utf8"); + const contentSize = MemoryManager.getByteSize(chunk.content); if (!this.memoryManager.canAddContent(contentSize)) { logInfo(`FullTextEngine: Memory limit reached at ${indexed} chunks`); break;