delucis / astro-netlify-cms

Integration to add Netlify CMS’s admin dashboard to any Astro project
161 stars 21 forks source link

Astro/Vite fails to properly mount Vue #18

Closed kcole93 closed 1 year ago

kcole93 commented 2 years ago

After installing astro-netlify-cms and adding a basic config entry in astro.config.mjs, Vue components failed to render as the Vue instance was seemingly not being properly mounted.

Fails to render Vue components

export default defineConfig({
  site: 'https://example.com',
  integrations: [
    mdx(),
    sitemap(),
    vue(),  // Vue integration declared before NetlifyCMS
    NetlifyCMS({
      config: {
        backend: {
          name: 'git-gateway',
          branch: 'master'
        },
        collections: [
          {
            name: 'posts',
            label: 'Blog Posts',
            folder: 'src/pages/blog',
            create: true,
            delete: true,
            fields: [
              { name: 'title', widget: 'string', label: 'Post Title' },
              { name: 'body', widget: 'markdown', label: 'Post Body' },
            ],
          },
        ]
      }
     }),
  ],
});

Properly renders Vue components

export default defineConfig({
  site: 'https://example.com',
  integrations: [
    mdx(),
    sitemap(),
    NetlifyCMS({
      config: {
        backend: {
          name: 'git-gateway',
          branch: 'master'
        },
        collections: [
          {
            name: 'posts',
            label: 'Blog Posts',
            folder: 'src/pages/blog',
            create: true,
            delete: true,
            fields: [
              { name: 'title', widget: 'string', label: 'Post Title' },
              { name: 'body', widget: 'markdown', label: 'Post Body' },
            ],
          },
        ]
      }
     }),
     vue(),
  ],
});

I'm not sure if this is an issue specific to the Astro-Netlify-CMS integration, or if it's on the Astro / Astro Vue integration side of things. However, it was difficult to figure out the cause other than that it having occurred after setting up Astro-Netlify-CMS.

In case it helps to identify the source, here's the error messages I was getting.

When rendering Vue components without a client directive:

[plugin:vite:vue] Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<)

When they are passed a client:only directive:

Vue warn: Component is missing template or render function

Perhaps it's worth mentioning in the installation / config instructions that this can be resolved by declaring the Astro-Netlify-CMS integration prior to Vue.

kcole93 commented 2 years ago

Here's a minimal reproduction on Stackblitz

delucis commented 2 years ago

Thanks for the detailed bug report @kcole93!

I'm wondering if this is due to this integration also installing @astrojs/react. 🤔 I'll try to take a look this week to see what's going on.

yacosta738 commented 1 year ago

I have the same issue with Vue components

bitmoji

kcole93 commented 1 year ago

Hi Chris, just a heads up that someone else in the Astro discord came across a similar issue with weird Vue errors that were fixed when the order of declaring Vue in astro.config.mjs is changed, so I think it's safe to say that the issue doesn't rest with the NetlifyCMS integration.

See Issue 4994 in the Astro repo.

delucis commented 1 year ago

Thanks for the heads up @kcole93 — appreciate it! In that case I think we can close this issue.

If anyone else finds themselves here, looking for a quick solution: try moving vue() after NetlifyCMS() in your integrations array.