Git Product home page Git Product logo

Comments (8)

SimoTod avatar SimoTod commented on May 27, 2024 1

Yeah, it works okay if you follow the defer rule we discussed above but if you put the library before livewire without defer, livewire will just override the code. :(

from alpine-magic-helpers.

SimoTod avatar SimoTod commented on May 27, 2024

Thanks for reporting the issue. We need to look into it (It must be something Livewire does) but it works correctly if you either

I don't think it's a problem with $screen, it's just that screen is the only helper that gets evaluated on startup.

I know that the readme doesn't suggest deferring the script but IMO magic helpers should always be deferred or added at the bottom of your body so it doesn't block the rendering of the page. I'm personally a big fan but we didn't agree internally.

Also, if you just need to hide a div based on screen size, a standard CSS rule is probably a better option.

from alpine-magic-helpers.

basepack avatar basepack commented on May 27, 2024

SimonTod thanks for the heads up! Indeed, the issue is gone then.

I think it is a good idea to mention this behavior at least at the $screen documentation, I added a PR for it.

from alpine-magic-helpers.

KevinBatdorf avatar KevinBatdorf commented on May 27, 2024

I know that the readme doesn't suggest deferring the script but IMO magic helpers should always be deferred or added at the bottom of your body so it doesn't block the rendering of the page. I'm personally a big fan but we didn't agree internally.

I'm okay with changing the docs. I think we will end up with people who put the Helpers script after Alpine with defer and it will break, but without defer, it still would probably work since Alpine is deferred. But let's update it and see what happens.

Alternatively I think Ryan did something with Spruce to ensure it's loaded in properly. We could try something like that. I haven't checked what he added yet though.

from alpine-magic-helpers.

SimoTod avatar SimoTod commented on May 27, 2024

Yep, putting it at the end of the page, after livewire, would work too. Tbh, it should work with and without defer in the original example so there could be something we can improve but i haven't looked into it yet.

from alpine-magic-helpers.

SimoTod avatar SimoTod commented on May 27, 2024

Okay, I had a look and unfortunately, it cannot be fixed in our repo.
All our helpers preserve any previous callback that is supposed to run before alpine doing

const alpine = window.deferLoadingAlpine || ((alpine) => alpine())

window.deferLoadingAlpine = function (callback) {
    AlpineWhateverMagicMethod.start()
    alpine(callback)
}

but livewire just overrides deferLoadingAlpine discarding any previously registered callback.

/* From livewire codebase */
window.deferLoadingAlpine = function (callback) {
    window.addEventListener('livewire:load', function () {
        callback();
    });
};

I'm going to close this issue since it's not strictly a helper issue.
We'll integrate something based on your PR in the readme soon, thanks.

from alpine-magic-helpers.

basepack avatar basepack commented on May 27, 2024

@SimoTod that's unfortunate. If I read this correctly there is a change required in the Livewire codebase for the Magic Helpers to register correctly.

from alpine-magic-helpers.

KevinBatdorf avatar KevinBatdorf commented on May 27, 2024

Could PR livewire too I suppose!

from alpine-magic-helpers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.