Forráskód Böngészése

Add warning to prevent Alpine from being loaded twice on the same page (#3565)

Caleb Porzio 2 éve
szülő
commit
3a75b62dd1
1 módosított fájl, 6 hozzáadás és 0 törlés
  1. 6 0
      packages/alpinejs/src/lifecycle.js

+ 6 - 0
packages/alpinejs/src/lifecycle.js

@@ -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')