Skip to content

fix(document): streamDocFinalize skips final content when only one editor element is present #162

Description

@jdmanring

Problem

streamDocFinalize() in static/js/document.js (on develop) writes the final streamed document content behind a combined guard:

const textarea = document.getElementById('doc-editor-textarea');
const codeEl   = document.getElementById('doc-editor-code');
if (textarea && codeEl) {
  const finalContent = docs.get(oldId)?.content || '';
  textarea.value = finalContent;
  codeEl.textContent = finalContent + '\n';
}

If either element is absent when finalize runs — while switching document modes or rebuilding the editor panel — the whole block is skipped and the final content is never written to the element that IS present, leaving stale/empty text at the end of a stream. The streaming deltas write each element independently; only finalize couples them.

Origin (important — FORK-ONLY)

This code is not upstream-inherited. upstream-mirror's streamDocFinalize has no such block. The combined guard was introduced on develop by commit 67268d2b ("perf(oom): pre-apply safe pieces from upstream PR #4661"), which copied #4661's doc-finalize code as a stopgap — including the exact piece that upstream reviewer gprocunier later flagged as a bug in #4661's own review. So this is a fork-only fix to our develop stopgap; there is no upstream target (upstream #4661 fixes its own copy in 0b830f1).

Fix

Write each element independently, computing final content once:

const finalContent = docs.get(oldId)?.content || '';
if (textarea) textarea.value = finalContent;
if (codeEl) codeEl.textContent = finalContent + '\n';

Classification: fork-only (branch from develop; merge to develop).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions