Initializing board buttons 4 times

Hello! My power up app is a part of my angular app. This is code of my url connecor (my-angular-app/…/power-up.html). Now console.log(‘Initializing board buttons’) is triggered 4 times. Why? Thanks for yours answers!

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Authorize</title>
</head>

<body>
    <script src="https://p.trellocdn.com/power-up.min.js"></script>
    <script>
        window['TrelloPowerUp'].initialize({
            'board-buttons': async (t, opts) => {
                console.log('Initializing board buttons');

                try {
                    const token = await t.getRestApi().getToken();

                    if (token) {
                        return [{
                            text: '..',
                            icon: {
                                dark: '..',
                                light: '..',
                            },
                            callback: async (t) => {
                                return t.modal({
                                    url: '/trello-power-up-auth',
                                    accentColor: '#0A429A',
                                    height: 500,
                                    fullscreen: true,
                                    title: '..',
                                    callback: () => t.closeModal(),
                                });
                            },
                            condition: 'admin'
                        }];
                    } else {

                        return [{
                            text: '..',
                            icon: {
                                dark: '..',
                                light: '..',
                            },
                            callback: (t) => {
                                return t.popup({
                                    height: 50,
                                    title: 'Authorize to continue',
                                    url: '.../auth-popup.html'
                                });
                            },
                            condition: 'admin'
                        }];
                    }
                } catch (error) {
                    console.error('Error during board-buttons initialization:', error);
                    return [];
                }
            }
        }, {
            appKey: '...',
            appName: '...',
            appAuthor: '...',
        });

    </script>
</body>

</html>

I also tried to do this to prevent this behavior:


 let currentContext = null;

        window['TrelloPowerUp'].initialize({
            'board-buttons': async function (t) {
                context = t.getContext();

                if (currentContext && currentContext !== context) {
                    return null;
                }

                currentContext = context;
                console.log('initialize!!!');

BUT It still causes errors.

image

1 Like