Tiniest timeout in index.js will fail plugin to load

If I have the slightest timeout in index.js (main entrypoint), plugin fails with menuItems error:

Log
Uncaught TypeError: Cannot read properties of null (reading 'menuItems')
    at e.exports.pushFullUpdate (uxp://uxp-internal/pluginmanager_scripts.js:2)
    at e.exports._pushFullUpdate (uxp://uxp-internal/pluginmanager_scripts.js:2)
    at uxp://uxp-internal/pluginmanager_scripts.js:2
    at uxp://uxp-internal/runtime_scripts_loader.js:2
pushFullUpdate @ uxp://uxp-internal/p…anager_scripts.js:2
_pushFullUpdate @ uxp://uxp-internal/p…anager_scripts.js:2
(anonymous) @ uxp://uxp-internal/p…anager_scripts.js:2
(anonymous) @ uxp://uxp-internal/r…scripts_loader.js:2

Which is impossible to debug


Minimal example to reproduce:

// index.js
import { entrypoints } from "uxp"

const myFunc = async () => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(true)
        }, 50)
    })
}

myFunc().then(() => {
    entrypoints.setup({
        panels: {
            "panel1": {
                create() {
                    return new Promise(function(resolve) {
                        const container = document.createElement("div")
                        container.className = "root"
                        container.innerHTML = "<p>PANEL</p>"

                        document.appendChild(container)
                        resolve(true)
                    })
                },

                menuItems: [{
                    id: "menuItemId",
                    label: "menuItem.label",
                    enabled: false,
                    checked: false,
                }],
            },
        },
    })

    console.log("ALL_DONE")
})

ALL_DONE is logged before the error
If you remove the timeout or make it like 5 ms, then panel loads

At which point menuItems is null? Is this expected? What am I missing?

Just noticed, that sometimes even without the timout panel fails to load with the same error :confused:
If the setup() is not in a .then(), it works every time

I think you need to call setup within first 300ms after panel load. It has a timeout.

Good thing we have this well documen… Oh, wait :grin:
Anyway :slight_smile: I’m accepting this as a solution, because it sounds exactly what it might be

This one is actually documented. E.g. here: https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/uxp/Entry%20Points/EntryPoints/

1 Like

I was on this page for hours and didn’t see that :man_facepalming: I honestly hate all of these docs pages formatting and structure overall… While reading, I found some texts on Photoshop docs are literally dedicated to XD :man_shrugging:

On the same page:

Why…?

Yes me too. It is better to read commits on github to see what is new and then memorize everything.

Recently I found out there is an option to hide progress bar in batchPlay. I did’t see it for about two years… such a cool feature. :smiley:

Most of the docs is generated from source code… same as a types.

I don’t know. XD is dead software already no need to learn it. Marketplace no longer accepts XD plugins

1 Like

Wait…There is??? I could use that!

1 Like