Skip to content

Feature request: a distinct diagnostic for clicks SuperDoc cannot place #4144

Open

Description

@ohcedar

Hosts have no documented way to tell "this click could not be placed" from a rendering failure, so a host that treats render-stage errors as fatal shuts the document down over a lost click.

What happens (superdoc 2.29.0)

Clicking painted deleted text while its tracked deletion is being rejected through the Document API reports this through onException:

{"diagnosticCode":"RENDER_ERROR","diagnosticStage":"render","severity":"error","internalCode":"worker-dom.failed",
 "message":"WorkerTransportError: Deleted pointer hit has no current canonical source owner"}

Afterwards the editor carried on in every check I ran: trackChanges.list and getText answered, a later click placed the caret and a typed character appeared, and export() returned a Blob, with no further exceptions.

One of the diagnostics emitted while a malformed document fails to open carries the same public code, stage and severity (and the same internalCode):

{"diagnosticCode":"RENDER_ERROR","diagnosticStage":"render","severity":"error","internalCode":"worker-dom.failed",
 "message":"Error: Worker DOM source did not complete: body-close-tag-missing-from-tail-context"}

So in 2.29.0 the unresolved-click diagnostic shares its diagnosticCode, diagnosticStage and severity with a diagnostic from a failed open, and no documented field marks it as a recoverable input failure. (The failed open as a whole can be recognised in other ways: it also emits PARSE_ERROR and never reaches ready. The difficulty is classifying the single event when it arrives mid-session.) The type docs describe internalCode as unstable debugging information and give message no stability guarantee, so matching on either is not a contract.

Request

A documented way to recognise "a pointer event could not be resolved" on the diagnostic itself. Any one of these would do:

  • a separate diagnosticCode or diagnosticStage for input resolution, or
  • severity: "warn" for these events, or
  • not reporting them through onException, if they are always recoverable.

Versions

click run malformed-document run
superdoc 2.29.0 (@superdoc/docx-engine 0.28.0) the event above, in 6 of 6 runs not ready; includes the matching RENDER_ERROR and a PARSE_ERROR
superdoc 2.30.0-next.13 (@superdoc/docx-engine 0.29.0-next.13) not reproduced with this harness (0 of 6 runs) not ready; PARSE_ERROR, no render diagnostic

I can't tell whether the race is gone in 2.30.0-next.13 or only narrower. If it can no longer happen, that settles this.

CDN build (dist-cdn/superdoc.min.js), Chromium 153.0.8010.12 (Playwright 1.63.0, headless), Node v24.21.0, macOS 27.0.1 arm64.

Repro

Two files, plus npm i superdoc@2.29.0 jszip@3.10.2 playwright@1.63.0 (and npx playwright install chromium if needed). node repro.mjs runs the click case; node repro.mjs . broken runs the malformed-document case. The script generates its own DOCX (8 paragraphs, each with one w:del/w:delText tracked deletion), serves DOCX Engine from the installed package so it runs offline, and blocks other off-origin requests.

The recipe: read the screen centres of the painted deleted runs (found by the track-delete class, which is only used to get coordinates). For each deletion, call trackChanges.decide({ decision: 'reject' }), click those centres with real mouse events while the call is in flight, then await it before starting the next.

index.html
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>SuperDoc onException demo</title>
  <link rel="stylesheet" href="/node_modules/superdoc/dist-cdn/superdoc.min.css">
  <script src="/node_modules/superdoc/dist-cdn/superdoc.min.js"></script>
</head>
<body style="margin:0">
  <div id="editor" style="height:100vh"></div>
  <script>
    window.exceptions = [];
    window.decided = [];
    window.ready = false;
    window.start = async (url) => {
      const blob = await (await fetch(url)).blob();
      window.sd = new SuperDoc({
        selector: '#editor',
        document: new File([blob], 'demo.docx', {
          type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        }),
        documentMode: 'editing',
        telemetry: { enabled: false },
        onReady: () => { window.ready = true; },
        onException: (p) => {
          window.exceptions.push({
            diagnosticCode: p.diagnosticCode,
            diagnosticStage: p.diagnosticStage,
            severity: p.severity,
            internalCode: p.internalCode,
            message: p.message ?? String(p.error),
            errorName: p.error?.name,
          });
        },
      });
    };
  </script>
</body>
</html>
repro.mjs
// Usage: node repro.mjs <dir whose node_modules has superdoc> [click|broken]
import http from 'node:http';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import JSZip from 'jszip';
import { chromium } from 'playwright';

const here = path.dirname(fileURLToPath(import.meta.url));
const pkgRoot = path.resolve(process.argv[2] ?? '.');
const mode = process.argv[3] ?? 'click';

// Synthetic DOCX: 8 paragraphs, each with kept text and one tracked deletion.
// 'broken' leaves word/document.xml unterminated so the document cannot open.
async function makeDocx(broken) {
  const paras = Array.from({ length: 8 }, (_, i) => `
    <w:p>
      <w:r><w:t xml:space="preserve">Paragraph ${i + 1} keeps this text. </w:t></w:r>
      <w:del w:id="${i + 1}" w:author="Reviewer" w:date="2024-01-01T00:00:00Z">
        <w:r><w:delText xml:space="preserve">This sentence was deleted with tracked changes on and is long enough to click. </w:delText></w:r>
      </w:del>
      <w:r><w:t xml:space="preserve">And this text stays.</w:t></w:r>
    </w:p>`).join('');
  const zip = new JSZip();
  zip.file('[Content_Types].xml', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
  <Default Extension="xml" ContentType="application/xml"/>
  <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>`);
  zip.file('_rels/.rels', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
</Relationships>`);
  const W = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
  zip.file('word/document.xml', broken
    ? `<w:document xmlns:w="${W}"><w:body><w:p><w:r><w:t>unclosed`
    : `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="${W}"><w:body>${paras}<w:sectPr/></w:body></w:document>`);
  return zip.generateAsync({ type: 'nodebuffer' });
}

const docx = await makeDocx(mode === 'broken');
const types = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css' };
const server = http.createServer((req, res) => {
  const url = decodeURIComponent(new URL(req.url, 'http://x').pathname);
  if (url === '/demo.docx') { res.writeHead(200); return res.end(docx); }
  const file = url.startsWith('/node_modules/') ? path.join(pkgRoot, url) : path.join(here, 'index.html');
  fs.readFile(file, (err, data) => {
    if (err) { res.writeHead(404); return res.end(); }
    res.writeHead(200, { 'content-type': types[path.extname(file)] ?? 'application/octet-stream' });
    res.end(data);
  });
});
await new Promise((r) => server.listen(0, '127.0.0.1', r));
const origin = `http://127.0.0.1:${server.address().port}`;

const browser = await chromium.launch();
const context = await browser.newContext({ viewport: { width: 1200, height: 900 } });
// Runs offline: the CDN build loads DOCX Engine from jsdelivr, so serve the
// same files from the installed @superdoc/docx-engine package. Everything
// else off-origin is blocked.
const engineCdn = /^https:\/\/cdn\.jsdelivr\.net\/npm\/@superdoc\/docx-engine@[^/]+\/([^?]*)/;
await context.route('**/*', (route) => {
  const url = route.request().url();
  const m = url.match(engineCdn);
  if (m) return route.fulfill({ path: path.join(pkgRoot, 'node_modules/@superdoc/docx-engine', m[1]), headers: { 'access-control-allow-origin': '*' } });
  if (url.startsWith(origin) || url.startsWith('blob:') || url.startsWith('data:')) return route.continue();
  return route.abort();
});
const page = await context.newPage();
page.on('pageerror', (e) => console.log('pageerror:', e.message));

const version = (p) => JSON.parse(fs.readFileSync(path.join(pkgRoot, 'node_modules', p, 'package.json'))).version;
console.log(`superdoc ${version('superdoc')}, @superdoc/docx-engine ${version('@superdoc/docx-engine')}, Chromium ${browser.version()}, Node ${process.version}, ${process.platform} ${process.arch}`);

const printExceptions = async (label, from = 0) => {
  const list = (await page.evaluate(() => window.exceptions)).slice(from);
  console.log(`${label}: onException calls = ${list.length}`);
  for (const e of list) console.log('  ' + JSON.stringify(e));
  return from + list.length;
};

try {
  await page.goto(origin + '/');
  await page.evaluate(() => window.start('/demo.docx'));

  if (mode === 'broken') {
    await page.waitForTimeout(8000);
    console.log('onReady fired:', await page.evaluate(() => window.ready));
    await printExceptions('broken document');
  } else {
    await page.waitForFunction(() => window.ready, null, { timeout: 30000 });
    await page.waitForSelector('[class*="track-delete"]');

    // Screen centres of the painted deleted text, read once up front.
    const targets = await page.evaluate(() => [...document.querySelectorAll('[class*="track-delete"]')]
      .map((el) => el.getBoundingClientRect())
      .filter((r) => r.width > 4 && r.height > 4)
      .map((r) => ({ x: r.left + r.width / 2, y: r.top + r.height / 2 })));
    const ids = await page.evaluate(async () => (await window.sd.getDocumentApi().trackChanges.list({}))
      .items.filter((c) => c.type === 'deletion').map((c) => c.id));
    console.log(`painted deletions: ${targets.length}, tracked deletions: ${ids.length}`);

    // Reject each deletion (not awaited) and click the painted deleted text meanwhile.
    for (const id of ids) {
      await page.evaluate((id) => {
        window.pending = Promise.resolve(window.sd.getDocumentApi().trackChanges.decide({ decision: 'reject', target: { id } }))
          .then((r) => window.decided.push(r?.success === true));
      }, id);
      for (const t of targets) await page.mouse.click(t.x, t.y);
      await page.evaluate(() => window.pending);
    }
    await page.waitForTimeout(1000);
    const seen = await printExceptions('reject while clicking');
    const decided = await page.evaluate(() => window.decided);
    console.log(`decide succeeded: ${decided.filter(Boolean).length} of ${decided.length}`);

    // The editor is fine afterwards.
    const read = () => page.evaluate(async () => {
      const d = window.sd.getDocumentApi();
      return { tracked: (await d.trackChanges.list({})).items.length, text: await d.getText({}) };
    });
    const before = await read();
    console.log(`after: trackChanges.list answers (${before.tracked} left); getText length ${before.text.length}`);
    const caret = await page.evaluate(() => {
      const walker = document.createTreeWalker(document.querySelector('.superdoc-page'), NodeFilter.SHOW_TEXT);
      let n;
      while ((n = walker.nextNode()) && !n.textContent.startsWith('Paragraph 1'));
      const range = document.createRange();
      range.setStart(n, 0); range.setEnd(n, 1);
      const r = range.getBoundingClientRect();
      return { x: r.left + 1, y: r.top + r.height / 2 };
    });
    await page.mouse.click(caret.x, caret.y);
    await page.keyboard.type('Q');
    await page.waitForTimeout(500);
    const after = await read();
    console.log(`after: clicked before "Paragraph 1" and typed Q -> text starts ${JSON.stringify(after.text.slice(0, 32))}`);
    const blob = await page.evaluate(async () => (await window.sd.export({ triggerDownload: false })).size);
    console.log(`after: export() returned ${blob} bytes`);
    await printExceptions('during the checks after', seen);
  }
} finally {
  await browser.close();
  server.close();
}
Output, 2.29.0

node repro.mjs:

superdoc 2.29.0, @superdoc/docx-engine 0.28.0, Chromium 153.0.8010.12, Node v24.21.0, darwin arm64
painted deletions: 8, tracked deletions: 8
reject while clicking: onException calls = 1
  {"diagnosticCode":"RENDER_ERROR","diagnosticStage":"render","severity":"error","internalCode":"worker-dom.failed","message":"WorkerTransportError: Deleted pointer hit has no current canonical source owner","errorName":"WorkerTransportError"}
decide succeeded: 8 of 8
after: trackChanges.list answers (0 left); getText length 1024
after: clicked before "Paragraph 1" and typed Q -> text starts "QParagraph 1 keeps this text. Th"
after: export() returned 1158 bytes
during the checks after: onException calls = 0

node repro.mjs . broken:

superdoc 2.29.0, @superdoc/docx-engine 0.28.0, Chromium 153.0.8010.12, Node v24.21.0, darwin arm64
onReady fired: false
broken document: onException calls = 5
  {"diagnosticCode":"RENDER_ERROR","diagnosticStage":"render","severity":"warn","internalCode":"render.page-geometry.failed","message":"page geometry could not be resolved: source coverage failed/cancelled","errorName":"Error"}
  {"diagnosticCode":"RENDER_ERROR","diagnosticStage":"render","severity":"error","internalCode":"source.complete-failed","message":"source-complete returned a failed terminal result","errorName":"Error"}
  {"diagnosticCode":"RENDER_ERROR","diagnosticStage":"render","severity":"error","internalCode":"worker-dom.failed","message":"Error: Worker DOM source did not complete: body-close-tag-missing-from-tail-context","errorName":"Error"}
  {"message":"Error: SuperDoc could not load the document editor.","errorName":"Error"}
  {"diagnosticCode":"PARSE_ERROR","diagnosticStage":"unzip","severity":"error","internalCode":"open-failed","message":"Worker DOM source did not complete: body-close-tag-missing-from-tail-context","errorName":"Error"}
Output, 2.30.0-next.13

node repro.mjs:

superdoc 2.30.0-next.13, @superdoc/docx-engine 0.29.0-next.13, Chromium 153.0.8010.12, Node v24.21.0, darwin arm64
painted deletions: 8, tracked deletions: 8
reject while clicking: onException calls = 0
decide succeeded: 8 of 8
after: trackChanges.list answers (0 left); getText length 1024
after: clicked before "Paragraph 1" and typed Q -> text starts "QParagraph 1 keeps this text. Th"
after: export() returned 1300 bytes
during the checks after: onException calls = 0

node repro.mjs . broken:

superdoc 2.30.0-next.13, @superdoc/docx-engine 0.29.0-next.13, Chromium 153.0.8010.12, Node v24.21.0, darwin arm64
onReady fired: false
broken document: onException calls = 2
  {"message":"Error: SuperDoc could not load the document editor.","errorName":"Error"}
  {"diagnosticCode":"PARSE_ERROR","diagnosticStage":"unzip","severity":"error","internalCode":"open-failed","message":"Document source is malformed: 1:114: unclosed tag: w:t","errorName":"Error"}

Activity

  1. added
    status: triage
    on Nov 9, 2026
  2. added theissue type on Nov 9, 2026
  3. caio-pizzol commented on Nov 10, 2026

    @caio-pizzol
    Contributor

    Thanks for the great repro! We saw the same error on 2.29.0, but it doesn't happen on the 2.30.0 prereleases or main. The race is gone, not just rarer. We're planning a big stable release soon that already includes this fix. If you need it before then, the next tag has it.

  4. self-assigned this
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: triage

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions