Skip to content
Discussion options

You must be logged in to vote

It's expected. Alpine tries to magically resolve functions and promises to remove complexity from the page. It was a design choice of the author which unfortunately won't fit your use case.
You can work around it with by wrapping the promise in a function and asking Alpine not to auto evaluate it.

<div x-data x-promise></div>

<script>
    let Prom = (Alpine) => {
        Alpine.directive('promise', (el, {}, {evaluate}) => {
            let foo = Alpine.dontAutoEvaluateFunctions(() => evaluate("() => new Promise(()=>{console.log('running')})"))()
            console.log(foo)
       })
    }
    document.addEventListener('alpine:init', () => {
        Prom(Alpine)
    })
</script>

<script s…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@crholm
Comment options

Comment options

You must be logged in to vote
5 replies
@crholm
Comment options

@ekwoka
Comment options

@SimoTod
Comment options

SimoTod Feb 24, 2025
Collaborator

@crholm
Comment options

@ekwoka
Comment options

Answer selected by crholm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #4549 on February 23, 2025 21:21.