Skip to content

Commit

Permalink
Add warning to prevent Alpine from being loaded twice on the same page (
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed May 10, 2023
1 parent ec73d44 commit 3a75b62
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/alpinejs/src/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { dispatch } from './utils/dispatch'
import { walk } from "./utils/walk"
import { warn } from './utils/warn'

let started = false

export function start() {
if (started) warn('Alpine has already been initialized on this page. Calling Alpine.start() more than once can cause problems.')

started = true

if (! document.body) warn('Unable to initialize. Trying to load Alpine before `<body>` is available. Did you forget to add `defer` in Alpine\'s `<script>` tag?')

dispatch(document, 'alpine:init')
Expand Down

0 comments on commit 3a75b62

Please sign in to comment.