diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.ts index 81eae41e1a..8cca352c78 100644 --- a/apps/client/src/components/note_context.ts +++ b/apps/client/src/components/note_context.ts @@ -261,14 +261,33 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded"> return true; } - const blob = await this.note.getBlob(); - if (!blob) { - return false; + // Store the initial decision about read-only status in the viewScope + // This will be "remembered" until the viewScope is refreshed + if (!this.viewScope) { + this.resetViewScope(); } - const sizeLimit = this.note.type === "text" ? options.getInt("autoReadonlySizeText") : options.getInt("autoReadonlySizeCode"); + // We've ensured viewScope exists by calling resetViewScope() if needed + const viewScope = this.viewScope as ViewScope; + + if (viewScope.readOnlyDecision === undefined) { + const blob = await this.note.getBlob(); + if (!blob) { + viewScope.readOnlyDecision = false; + return false; + } + + const sizeLimit = this.note.type === "text" + ? options.getInt("autoReadonlySizeText") + : options.getInt("autoReadonlySizeCode"); + + viewScope.readOnlyDecision = Boolean(sizeLimit && + blob.contentLength > sizeLimit && + !this.note.isLabelTruthy("autoReadOnlyDisabled")); + } - return sizeLimit && blob.contentLength > sizeLimit && !this.note.isLabelTruthy("autoReadOnlyDisabled"); + // Return the cached decision, which won't change until viewScope is reset + return viewScope.readOnlyDecision || false; } async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts index a0d464741b..dcfbd16e20 100644 --- a/apps/client/src/services/link.ts +++ b/apps/client/src/services/link.ts @@ -48,6 +48,7 @@ export interface ViewScope { viewMode?: ViewMode; attachmentId?: string; readOnlyTemporarilyDisabled?: boolean; + readOnlyDecision?: boolean; highlightsListPreviousVisible?: boolean; highlightsListTemporarilyHidden?: boolean; tocTemporarilyHidden?: boolean;