primocms / primo

Primo is a visual CMS with a built-in code editor, Svelte blocks, and static site generator.
https://primocms.org
MIT License
1.98k stars 515 forks source link

svelte:window causes crash #229

Closed rallisf1 closed 1 year ago

rallisf1 commented 1 year ago

I am using <svelte:window bind:innerWidth={vw} bind:innerHeight={vh} /> in one of my pages so I can dynamically control some responsive elements. Up until a few versions ago it would work flawlessly but in the latest version (primo v1.7.2 server v1.0.0--beta.2) it makes the page not to render with

Worker caught an error: Error: 'default' is not exported by ./Component_1.svelte, imported by ./App.svelte
Error: 'default' is not exported by ./Component_1.svelte, imported by ./App.svelte

showing in the console and its index.html only has

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

<head>
    <meta name="generator" content="Primo" />
    undefined
    <style>
        undefined
    </style>
</head>

<body id="page">
    undefined
    <script type="module">
        const path = window.location.pathname === '/' ? '' : window.location.pathname
        const [{
            default: App
        }, data] = await Promise.all([
            import(path + '/_module.js'),
            fetch('/en.json').then(res => res.json())
        ]).catch(e => console.error(e))
        new App({
            target: document.querySelector('body'),
            hydrate: true,
        })
    </script>
</body>

</html>

with no _module.js getting generated either.

I have replaced svelte:window with some js that does the same job for now.

P.S. This might only affect the server, I am not using a desktop client.

mateomorris commented 1 year ago

Glad you caught this. I faced the same thing before but didn't look deeper into it; turns out it was caused by a recent update that sped up compilation by compiling all the components at the same time instead of independently, but since it automatically nests the components in wrapper divs, <svelte window: was causing a silent compilation error.

Fixed by extracting <svelte:window and moving it outside the wrapper divs; will need to do the same thing for other svelte tags that can't be nested at some point.

mateomorris commented 1 year ago

Here's the change https://github.com/primodotso/primo-server/commit/2553329da179108850c4b07e2e8bddce891e0639

Go ahead and update server & lemme know if that does it.