OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
677 stars 95 forks source link

[WordApi] field.range.insertText() fails for a tracked field #4891

Open adomasven opened 1 month ago

adomasven commented 1 month ago

Word Online

let tracked = [];
let field;
await Word.run(async (context) => {
    const selection = context.document.getSelection().getRange();
    field = selection.insertField('Start', 'Addin');
    field.code = `ADDIN test`;
    field.result.insertHtml("<b>Test1</b>", "Start");
    await context.sync();
    field.code = `ADDIN test1after`
    field.track();
    field.result.track();
    tracked.push(field);
    tracked.push(field.result);
    await context.sync();
});
await Word.run(tracked, async (context) => {
    // NOTE Uncomment to make this work
    // let fields = context.document.body.fields.load({ result: { text: true } });
    // await context.sync();
    // field = fields.items[0];
    field.result.insertText("", "Replace");
    await context.sync();
    // Throws Sorry, something went wrong. Check the OfficeExtension.Error.debugInfo for more information. 
});

This certainly used to work before (last tested at the start of June 2024). In our actual extension code I get an even weirder bug down the line with tracked objects, but when attempting to write a reproduction case for it I ran into this simpler issue.

microsoft-github-policy-service[bot] commented 1 month ago

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

shanshanzheng-dev commented 1 month ago

Hi @adomasven Thanks for reporting this issue. We'll take a look and report back if we have a suggestion for you.