Skip to content

contentControls.insertBefore refused with CAPABILITY_UNAVAILABLE since @superdoc/sdk 2.27.0 #4165

Todo

Description

@nandoofz

Summary

contentControls.insertBefore stopped working for block-level content controls in @superdoc/sdk 2.27.0 and is still refused in 2.31.0. The host answers:

CAPABILITY_UNAVAILABLE: Content-control mutation is not supported by the typed transaction path.

The same call, on the same document, succeeds in 2.26.0. We use it to write a paragraph before a content control that must stay verbatim, so this blocks us from upgrading past 2.26.0.

Versions

@superdoc/sdk result
2.26.0 success: true, appliedChangeMode: "direct"
2.27.0 CAPABILITY_UNAVAILABLE
2.28.0 CAPABILITY_UNAVAILABLE
2.30.0 CAPABILITY_UNAVAILABLE
2.31.0 CAPABILITY_UNAVAILABLE

Node 26, Windows x64 (@superdoc/sdk-windows-x64).

Reproduction

A one-cell table whose cell holds a content control is enough. This script writes it, so there is no attachment to download:

import zipfile

BODY = """
<w:tbl>
  <w:tblPr><w:tblW w:w="9071" w:type="dxa"/></w:tblPr>
  <w:tblGrid><w:gridCol w:w="9071"/></w:tblGrid>
  <w:tr><w:tc>
    <w:tcPr><w:tcW w:w="9071" w:type="dxa"/></w:tcPr>
    <w:sdt>
      <w:sdtPr><w:tag w:val="fixed"/><w:id w:val="101"/></w:sdtPr>
      <w:sdtContent>
        <w:p><w:r><w:t xml:space="preserve">Fixed text inside the control.</w:t></w:r></w:p>
      </w:sdtContent>
    </w:sdt>
  </w:tc></w:tr>
</w:tbl>
<w:p/>
"""

NS = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"'
DOCUMENT = (
    '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
    "<w:document " + NS + "><w:body>" + BODY + "<w:sectPr/></w:body></w:document>"
)
CONTENT_TYPES = (
    '<?xml version="1.0" encoding="UTF-8"?>'
    '<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>"
)
RELS = (
    '<?xml version="1.0" encoding="UTF-8"?>'
    '<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>'
)

with zipfile.ZipFile("sdt-in-cell.docx", "w", zipfile.ZIP_DEFLATED) as z:
    z.writestr("[Content_Types].xml", CONTENT_TYPES)
    z.writestr("_rels/.rels", RELS)
    z.writestr("word/document.xml", DOCUMENT)
import { createSuperDocClient } from '@superdoc/sdk'

const client = createSuperDocClient({ user: { name: 'Repro' } })
await client.connect()
const doc = await client.open({ doc: 'sdt-in-cell.docx' })

const caps = await doc.capabilities.get({})
console.log(JSON.stringify(caps.operations['contentControls.insertBefore']))

const { items } = await doc.contentControls.list({ limit: 10 })
await doc.contentControls.insertBefore({
  target: items[0].target,
  content: 'A paragraph written before the control.',
  format: 'text',
})
await client.dispose()

Expected: a paragraph is created before the control, as in 2.26.0.
Actual: on 2.27.0 and later the call throws CAPABILITY_UNAVAILABLE.

Two things that may help

capabilities.get disagrees with the host. On 2.31.0 it reports the operation as usable right before the refusal:

{ "available": true, "tracked": true, "trackedSupport": "always", "dryRun": true }

On 2.27.0 it reports available: true with trackedSupport: "conditional" and reasons: ["TARGET_CONTEXT_REQUIRED"]. Either way a caller that checks capabilities first is told the call will work. If the refusal is intended, it would help a lot if capabilities.get reported it, since that is what we would branch on.

It is not only controls inside table cells. In another document of ours, a control holding four paragraphs at the end of the body is refused, while a control holding four paragraphs and a table earlier in the same document is accepted. We could not work out the predicate from the outside. The lock value makes no difference: sdtLocked, sdtContentLocked and no lock at all are all refused in the minimal case above.

What we tried instead

  • create.paragraph with at: { kind: 'before', target: <the control> } answers INVALID_TARGET: create.paragraph only supports before/after placement relative to paragraph-like blocks or top-level tables; received sdt.
  • blocks.move with the control as destination answers INVALID_ARGUMENT: blocks.move destination.nodeType must be paragraph, heading, or listItem; got "sdt", although DocBlocksMoveParams lists sdt among the accepted node types.

Creating the paragraph before the first top-level block of the body does work, so we have a way around it for one of the two shapes. We would rather not build on that if insertBefore is meant to keep working.

Thanks for looking at this.

Activity

  1. added
    status: triage
    on Nov 23, 2026
  2. added theissue type on Nov 23, 2026
  3. nandoofz commented on Nov 23, 2026

    @nandoofz
    Author

    One more thing on the impact, now that we have bisected the rest of our suite.

    This is a breaking change for us, and it currently pins us to 2.26.0. We cannot adopt any release from 2.27.0 onward, because contentControls.insertBefore is how we write a paragraph before a content control that has to stay verbatim, and that path is in production. On 2.27.0 and later that feature stops working, and the user gets an error instead of a document.

    The practical cost is that we also cannot take the fixes we were waiting for. #4012 was fixed in 2.30.0 and we confirmed it on our own documents: the comparison that used to be refused now applies cleanly. We would like to ship that, and we cannot, because the same upgrade would break the other feature.

    So our position today is that 2.26.0 is the last release we can run, and every later one costs us something that works.

    Two things would unblock us, and either is enough:

    1. contentControls.insertBefore works again for the targets it accepted in 2.26.0.
    2. Or, if the refusal is deliberate, a supported way to insert a block immediately before a content control. Today create.paragraph with at: { kind: 'before', target: <the control> } and blocks.move with the control as destination both refuse on the node type, so there is no replacement we could migrate to. If one of them is meant to accept an sdt target, that alone would solve it for us.

    Happy to test a build against both our real documents and the minimal case above, and to report back here. Thanks.

  4. added
    status: investigating
    and removed
    status: triage
    on Nov 24, 2026
  5. linear-code commented on Nov 24, 2026

    @linear-code
  6. added
    status: queued
    and removed
    status: investigating
    on Nov 24, 2026
  7. caio-pizzol commented on Nov 24, 2026

    @caio-pizzol
    Contributor

    Thanks for the repro, it reproduced right away.

    This is a regression from 2.27.0. insertBefore and insertAfter now refuse when the new paragraph would go inside a table cell or right next to a table. Your other document likely has a control right after a table. capabilities and dryRun also say yes before the real check runs, which is why they don't warn you.

    We're tracking both and will post here when a fix ships.

  8. vivienne-sd commented on Nov 24, 2026

    @vivienne-sd
    Collaborator

    Hi @nandoofz ! Thanks for reporting--I was able to reproduce this failure with your minimal example and confirmed the regression started in SDK 2.27.0.

    This's logged for the team, and we're working on getting a fix out. I'll update you here as soon as it lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: queued

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions