From 820eee334b66e40d9e794daab04d0d1cf48f0185 Mon Sep 17 00:00:00 2001 From: jasonlav Date: Wed, 22 Jan 2025 00:46:42 -0700 Subject: [PATCH] fix(alpinejs): start on DOMContentLoaded (#13014) Co-authored-by: Florian Lefebvre --- .changeset/tall-bears-return.md | 5 +++++ packages/integrations/alpinejs/src/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/tall-bears-return.md diff --git a/.changeset/tall-bears-return.md b/.changeset/tall-bears-return.md new file mode 100644 index 000000000000..71fe7299deb0 --- /dev/null +++ b/.changeset/tall-bears-return.md @@ -0,0 +1,5 @@ +--- +"@astrojs/alpinejs": patch +--- + +Fixes an issue with user scripts running after `Alpine.start()` diff --git a/packages/integrations/alpinejs/src/index.ts b/packages/integrations/alpinejs/src/index.ts index 86e09347eb39..f363d9e22b7e 100644 --- a/packages/integrations/alpinejs/src/index.ts +++ b/packages/integrations/alpinejs/src/index.ts @@ -98,7 +98,7 @@ export default function createPlugin(options?: Options): AstroIntegration { import { setup } from 'virtual:@astrojs/alpinejs/entrypoint'; setup(Alpine); window.Alpine = Alpine; -Alpine.start();`, +document.addEventListener('DOMContentLoaded', () => Alpine.start());` ); updateConfig({ vite: {