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 <noreply@anthropic.com>
This commit is contained in:
Logan Yang 2026-02-24 13:01:51 -08:00 committed by GitHub
parent 871f66bddf
commit efda62a6ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View file

@ -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);
}

View file

@ -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;