Skip to content

Rejecting a tracked replacement of an unnumbered paragraph loses its style and direct formatting #4158

Open

Description

@ohcedar

Summary

Through createSuperDocClient, rejecting a tracked whole-paragraph content replacement restores the original text but loses the defined custom paragraph style reference on an unnumbered paragraph; separate cases also lose direct indentation, alignment and spacing. The baseline preserves these properties, while current and the tested prerelease lose them. The numbered-paragraph control preserves all five tested properties on every tested version; no numbering-loss claim is made.

Versions

Tested on Node.js 24.21.0 with JSZip 3.10.1.

Package Baseline Current Tested prerelease
superdoc 2.29.0 2.31.0 2.32.0-next.14
@superdoc/sdk 2.26.0 2.28.0 2.29.0-next.14
@superdoc/docx-engine 0.28.0 0.30.0 0.31.0-next.14

The reproduction executes the documented SDK entry point. The superdoc package is installed to identify the release line; no browser or Word rendering result is asserted.

Reproduction

The leading case uses this body in word/document.xml (w is the standard WordprocessingML namespace):

<w:p><w:pPr><w:pStyle w:val="ExampleStyle"/></w:pPr>
  <w:r><w:t>Alpha old beta.</w:t></w:r>
</w:p>
<w:p><w:r><w:t>Gamma delta.</w:t></w:r></w:p>

The generated package defines the custom style in word/styles.xml; it is not a dangling style reference:

<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:style w:type="paragraph" w:default="1" w:styleId="Normal">
    <w:name w:val="Normal"/>
  </w:style>
  <w:style w:type="paragraph" w:customStyle="1" w:styleId="ExampleStyle">
    <w:name w:val="Example Style"/><w:basedOn w:val="Normal"/>
    <w:pPr><w:spacing w:after="240"/><w:jc w:val="right"/></w:pPr>
    <w:rPr><w:b/></w:rPr>
  </w:style>
</w:styles>

word/_rels/document.xml.rels links it:

<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rIdStyles" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
</Relationships>

The content-types part includes:

<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>

Run the following on the synthetic file:

import {createSuperDocClient} from '@superdoc/sdk';
const client = createSuperDocClient({stateDir:'./state'});
await client.connect();
try {
  const doc = await client.open({doc:'input.docx', userName:'Example Author'});
  try {
    const b = (await doc.blocks.list({includeText:true})).blocks[0];
    await doc.replace({
      target:{kind:'block', nodeType:b.nodeType, nodeId:b.nodeId},
      content:[{kind:'paragraph', id:'replacement', paragraph:{inlines:[
        {kind:'run', run:{text:'Alpha '}},
        {kind:'run', run:{text:'new', props:{bold:true}}},
        {kind:'run', run:{text:' beta.'}}
      ]}}]
    }, {changeMode:'tracked'});
    const ids = (await doc.trackChanges.list({})).items.map(x => x.id);
    await doc.trackChanges.decide({decision:'reject', target:{kind:'ids', ids}});
    await doc.save({out:'rejected.docx', force:true});
  } finally { await doc.close({discard:true}); }
} finally { await client.dispose(); }

On fresh documents, the script also tests these properties individually inside the first paragraph's w:pPr, then combines these three properties with the custom style reference:

<w:ind w:left="720" w:firstLine="240"/>
<w:jc w:val="center"/>
<w:spacing w:after="160"/>

The numbered control contains the custom style reference and all three direct properties plus:

<w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr>

For that control, the script also generates word/numbering.xml with a decimal definition, a numId=1 instance, its document relationship, and the numbering content type. The full package construction and all calls are included below.

Actual

“Kept” means the exported paragraph still has the same property values after rejection; insignificant whitespace before an XML closing slash is ignored. Every untouched-export control keeps its input properties. Every replacement and rejection succeeds, the original text returns, pending changes drop from two to zero, and ExampleStyle remains defined in the styles part.

Case / tested property Baseline 2.29.0 Current 2.31.0 Tested prerelease 2.32.0-next.14
Unnumbered custom style: pStyle=ExampleStyle Kept Lost Lost
Unnumbered indentation: ind left=720, firstLine=240 Kept Lost Lost
Unnumbered alignment: jc=center Kept Lost Lost
Unnumbered spacing: spacing after=160 Kept Lost Lost
Unnumbered combined: pStyle, ind, jc, spacing All kept All lost All lost
Numbered control: pStyle, ind, jc, spacing, numPr All kept All kept All kept

Expected

Rejecting the replacement should restore the unnumbered paragraph's original style reference and direct formatting, as on the baseline. The tracked-change documentation describes rejection as restoring the change's before-state. The expectation concerns restoration after rejection, not preservation while the proposed whole-paragraph replacement is pending.

Related but different: #3882 concerns paragraph properties on a surviving successor when accepting a tracked whole-block deletion on v1. This report concerns rejecting replacement of an unnumbered paragraph through the v2 SDK.

Complete standalone Node reproduction and installation instructions
// Node.js 24 (tested on 24.21.0). In a new directory containing this file:
// npm init -y
// npm install --save-exact superdoc@2.31.0 @superdoc/sdk@2.28.0 @superdoc/docx-engine@0.30.0 jszip@3.10.1
// node repro.mjs
// To compare other pinned installs: NODE_MODULES=/absolute/path/to/node_modules node repro.mjs
// Uses createSuperDocClient and public document methods. No browser required.
// Temporary DOCX files are created beside this script and removed on completion.
import fs from 'node:fs/promises';
import path from 'node:path';
import {createRequire} from 'node:module';
import {fileURLToPath, pathToFileURL} from 'node:url';
const here = path.dirname(fileURLToPath(import.meta.url));
const nm = path.resolve(process.env.NODE_MODULES || path.join(here, 'node_modules'));
const require = createRequire(path.join(nm, '_resolver.cjs'));
const JSZip = require('jszip');
const {createSuperDocClient} = await import(pathToFileURL(require.resolve('@superdoc/sdk')));
const version = async name => JSON.parse(await fs.readFile(path.join(nm, name, 'package.json'), 'utf8')).version;
console.log('versions | superdoc=' + await version('superdoc') + ' | sdk=' + await version('@superdoc/sdk') + ' | engine=' + await version('@superdoc/docx-engine'));
const work = await fs.mkdtemp(path.join(here, '.run-'));
const W = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
const p = (text, pr = '') => '<w:p>' + pr + '<w:r><w:t>' + text + '</w:t></w:r></w:p>';
async function fixture(body, numbered) {
  const z = new JSZip();
  z.file('[Content_Types].xml', '<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>');
  z.file('_rels/.rels', '<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>');
  z.file('word/document.xml', '<w:document xmlns:w="' + W + '"><w:body>' + body + '<w:sectPr/></w:body></w:document>');
  z.file('word/styles.xml', '<w:styles xmlns:w="' + W + '"><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style><w:style w:type="paragraph" w:customStyle="1" w:styleId="ExampleStyle"><w:name w:val="Example Style"/><w:basedOn w:val="Normal"/><w:pPr><w:spacing w:after="240"/><w:jc w:val="right"/></w:pPr><w:rPr><w:b/></w:rPr></w:style></w:styles>');
  let rels = '<Relationship Id="rIdStyles" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>';
  let types = '<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>';
  if (numbered) {
    z.file('word/numbering.xml', '<w:numbering xmlns:w="' + W + '"><w:abstractNum w:abstractNumId="0"><w:multiLevelType w:val="singleLevel"/><w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:lvlJc w:val="left"/></w:lvl></w:abstractNum><w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num></w:numbering>');
    rels += '<Relationship Id="rIdNumbering" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/>';
    types += '<Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>';
  }
  z.file('word/_rels/document.xml.rels', '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' + rels + '</Relationships>');
  z.file('[Content_Types].xml', (await z.file('[Content_Types].xml').async('string')).replace('</Types>', types + '</Types>'));
  return z.generateAsync({type:'nodebuffer'});
}
const client = createSuperDocClient({stateDir:path.join(work, 'state')});
const addr = b => ({kind:'block', nodeType:b.nodeType, nodeId:b.nodeId});
const style = '<w:pStyle w:val="ExampleStyle"/>';
const indent = '<w:ind w:left="720" w:firstLine="240"/>';
const alignment = '<w:jc w:val="center"/>';
const spacing = '<w:spacing w:after="160"/>';
const num = '<w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr>';
const cases = [
  ['custom-style', style],
  ['indentation', indent],
  ['alignment', alignment],
  ['spacing', spacing],
  ['combined', style + indent + spacing + alignment],
  ['numbered-control', style + num + indent + spacing + alignment]
];
async function describe(name, stage, bytes) {
  const z = await JSZip.loadAsync(bytes);
  const x = await z.file('word/document.xml').async('string');
  const para = [...x.matchAll(/<w:p\b[^>]*>[\s\S]*?<\/w:p>/g)].find(m => m[0].includes('Alpha'))?.[0];
  if (!para) throw new Error('Target paragraph not found');
  const fields = ['pStyle','ind','jc','spacing','numPr'].map(tag => {
    const re = new RegExp('<w:' + tag + '\\b[^>]*(?:/>|>[\\s\\S]*?</w:' + tag + '>)');
    return tag + '=' + (para.match(re)?.[0] ?? '(none)');
  });
  const styles = await z.file('word/styles.xml').async('string');
  const text = [...para.matchAll(/<w:t\b[^>]*>([^<]*)<\/w:t>/g)].map(m => m[1]).join('');
  console.log(name + ' | ' + stage + ' | ' + fields.join(' | ') + ' | styleDefined=' + styles.includes('w:styleId="ExampleStyle"') + ' | text=' + text);
}
await client.connect();
try {
  console.log('host | sdk');
  console.log('case | stage | pStyle | ind | jc | spacing | numPr | styleDefined | text');
  for (const [name, properties] of cases) {
    const input = await fixture(p('Alpha old beta.', '<w:pPr>' + properties + '</w:pPr>') + p('Gamma delta.'), name === 'numbered-control');
    const file = path.join(work, name + '.docx');
    await fs.writeFile(file, input);
    const doc = await client.open({doc:file, userName:'Example Author'});
    const save = async () => {
      const out = path.join(work, 'export.docx');
      await doc.save({out, force:true});
      return fs.readFile(out);
    };
    try {
      await describe(name, 'input', input);
      await describe(name, 'untouched', await save());
      const b = (await doc.blocks.list({includeText:true})).blocks[0];
      const content = [{kind:'paragraph', id:'replacement', paragraph:{inlines:[
        {kind:'run', run:{text:'Alpha '}},
        {kind:'run', run:{text:'new', props:{bold:true}}},
        {kind:'run', run:{text:' beta.'}}
      ]}}];
      const replacement = await doc.replace({target:addr(b), content}, {changeMode:'tracked'});
      const ids = (await doc.trackChanges.list({})).items.map(x => x.id);
      const decision = await doc.trackChanges.decide({decision:'reject', target:{kind:'ids', ids}});
      console.log(name + ' | result | replace=' + (replacement.receipt ?? replacement).success + ' | changes=' + ids.length + ' | reject=' + decision.success + ' | pending=' + (await doc.trackChanges.list({})).items.length);
      await describe(name, 'rejected', await save());
    } finally { await doc.close({discard:true}); }
  }
} finally { await client.dispose(); await fs.rm(work, {recursive:true, force:true}); }

Activity

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

    @caio-pizzol
    Contributor

    Thanks for the clear repro! Confirmed. Since SDK 2.27.0, a tracked paragraph replace drops the paragraph's formatting, so rejecting it can't bring the formatting back. We also found a related bug where numbered paragraphs damage the next paragraph. We're tracking both and will update here when they're fixed.

  4. added
    status: queued
    and removed
    status: triage
    on Nov 13, 2026
  5. self-assigned this
    on Nov 13, 2026
  6. added
    status: in-progress
    status: awaiting-release
    status: ready-for-validation
    status: done
    and removed
    status: queued
    status: in-progress
    status: awaiting-release
    status: ready-for-validation
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: done

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions