Error when trying to use selectedText in Context Menu Inline Dialog

Hi there,

today, I got this error when trying to use the selected text in my forge app which is providing an inline dialog called from the context menu

There was an error invoking the function - Cannot read property 'selectedText' of undefined
TypeError: Cannot read property 'selectedText' of undefined
    at Object.App [as type] (webpack:///src/index.jsx:6)
    at /tmp/tunnel82xWGVL825Cce/index.js:9054:36
    at asyncMap (webpack:///node_modules/@forge/ui/dist/cjs/reconcile.js:13)
    at /tmp/tunnel82xWGVL825Cce/index.js:9014:35
    at Object.exports.processAuxElement (webpack:///node_modules/@forge/ui/dist/cjs/reconcile.js:113)
    at /tmp/tunnel82xWGVL825Cce/index.js:8939:49
    at Reference.value (bootstrap.js:1:8667)

I didn’t change anything in my code, 2 weeks ago it was working. Now it is not working anymore. Do you have an idea why?

I try to get the selected text in my code this way:

const {extensionContext: {selectedText}} = useProductContext();

Why is it not working anymore?

Hi @ij-s,

I just attempted to reproduce using a new confluence:contextMenu UI kit extension and the code to get the selectedText does not cause the same issue for me, but instead works as expected. Could you confirm that the issue is still happening for you? If it is, then would you be able to share your version of @forge/ui and possibly the full app code (or at least a minimal reproducible example)?

Hi @kchan,

thanks for your reply. In the meantime I was able to fix the issue by myself. I used the code snippet from one of the example apps to get the selected text. This one worked for me:

const { extensionContext, contentId } = useProductContext();

  let selectedText;
  if (isContextMenuExtensionContext(extensionContext)) {
    selectedText = extensionContext.selectedText;
1 Like