decorateWidget no longer working

AI-generated summary

In a support thread titled ‘decorateWidget no longer working,’ bencf reported that their custom navbar, previously working via a decorateWidget script in the theme’s </head>, suddenly stopped rendering after an attempted edit. No console errors were visible except a 404 for a JS file, and even basic console.log tests failed to output. xrav3nz identified the issue as a Discourse bug fixed in commit 99d1ded3, advising bencf to update to the latest Discourse version and force a cache rebuild by editing the JS (e.g., adding/removing whitespace). bencf confirmed the fix worked and thanked xrav3nz.

I was using the following code in the </head> area of my customized theme. It was working fine, my custom navbar appeared. I tried to add another element to the custom navbar, and on preview nothing appeared. I tried to change the code back and it still didn’t work. I did some searching and can’t find any information on this, and also can’t find any errors in the console or on the page besides Failed to load resource: the server responded with a status of 404 () for https://mysite.com/javascripts/3804c7ea6ae9ec374a92e92086024dcdac103c0d.js.

I have some custom CSS as well to hide other elements I don’t want, but looking at the source, I don’t think that’s what’s going on since the elements don’t even seem to be created.

And when I replace this code with the following, I don’t get any console output besides that 404:

<script>console.log("working");</script>

Any ideas on what is wrong or what I could look at to try to fix it?

api.decorateWidget('home-logo:after', helper => {
    return helper.h('div', [
        helper.h('div#banner_container', [
            helper.h('a', {
                href: 'https://mysite.com'
            }, helper.h('img#header_word_logo', {
                    src: 'https://mysite.com/uploads/default/original/1X/imgcode.png'
                })
            )
        ]),
        helper.h('ul#header_menu', [
            helper.h('li', [
                helper.h('a', {
                    href:'https://www.mysite.com/1',
                    title: 'Section1'
                }, 'Section1'),
            ]),
            helper.h('li', [
                helper.h('a', {
                    href:'https://www.mysite.com/2',
                    title: 'Section2'
                }, 'Section2'),
            ]),
            helper.h('li', [
                helper.h('a.current_page_item', {
                    href:'https://www.mysite.com/3',
                    title: 'Section3'
                }, 'Section3'),
            ]),
            helper.h('li', [
                helper.h('a', {
                    href:'https://www.mysite.com/4',
                    title: 'Section4'
                }, 'Section4'),
            ]),
            helper.h('li', [
                helper.h('a', {
                    href:'https://www.mysite.com/5',
                    title: 'Section5'
                }, 'Section5'),
            ]),
        ]),
    ]);
});
</script>

Thank you for any and all help in advance!

Hey Ben, this has been fixed with https://github.com/discourse/discourse/commit/99d1ded3b3a2767617bbee9824e93eb57f135864. Could you please update your site to latest and try again?

After the update, you may need to edit your custom JavaScript (adding/removing a trailing space will do) to trigger a cache rebuild to see the effects.

That was the issue, thank you so much @xrav3nz!