YouTubevideo· Aug 15, 2025· 12:51
It's been a long week. I'm still recovering from Laravel. There's been a ton of new AI things that have been added. More videos to come on that. But I'm really excited for something that kind of got announced or at least teased last week and it's not fully out yet, but I wanted to make a video about why I think LiveWire 4 changes everything.
Now, if you're new to the channel, I've been using LiveWire ever since I started using Laravel. So when Caleb Porzu gave me a little bit of a teaser about his talk before he even gave the talk at Laracon, I already knew this would change how people see LiveWire, but then how you create with LiveWire as well.
And so why do I think this changes everything within LiveWire? Well, Caleb also kind of set this up as well. It's going to change things not like breaking changes, at least so far. It's going to change things because of how people perceive LiveWire. I even made a video about three things that Laravel livewire is not because most people think it's a certain way. But it's also, you know, just not very uh perceived well from the hey, let me get started with this because it is different.
It is interesting to think about and I think these changes make it a lot easier to get started with, but then two to write LiveWire better and it's just better in general. So why don't we dive in? A lot of this is mostly going to come from Tony Leah's blog post, LiveWire 4, the future of PHP components, which I'm going to just walk through. It starts off with knowing that the whole community is forked that Caleb Porzio said it's a lot of people there's three ways to write Livewire traditionally and then you have volt class base which is single file components using classbased structure and PHP and then functional.
And so how do you fix that? Well, there's just one way to write livewire in LiveWire 4. You just write uh make livewire and it turns it into a single file component. There's no more vault.
And by default, this is a livewire.php component. And more on that in a little bit, but it doesn't have to be. It's just blade. It's just using a separate parser to do all the fancy stuff that's happening behind the scenes. And some of this is starting to get into why I think it's going to be a lot easier to write Livewire components, especially for newcomers. One, there's no more at script directive. you just use a script tag and then you can reference it by using this dot. Of course, you can still use this dollar sign wire which is what you currently have to use.
But this dot just seems more I don't know JavaScripty in a lot of ways. Speaking about JavaScripty, you can now intercept specific parts of the request life cycle. A lot of times this is helpful if you need to do something on the client before waiting for a response from the server. This makes optimistic UI that much easier. But this part is actually one of my favorites. You're writing in LiveWire, specifically LiveWire Volt single page components. Most people complain, "Hey, this isn't easy when it becomes a 200 plus line component. Now I have to break it up into its own thing."
Well, LiveWire does that for you. Now, you can just make the component and then pass a d-mfc. And if that component already exists, then voila, it turns it into this. Hey, here's your JS, here's your PHP, here's your blade. And also, ooh, here's your test. I think collocation is great. And Caleb talked about this from stage.
JavaScript does it. Spelt does it. Uh, you know, there's so many things outside of the PHP ecosystem that do something like this. You have your counter, and he used a cool little emoji, the the vault bolt emoji here, which I love. Uh, but you you see this a lot outside of PHP, outside of Laravel. have your um your script, you have any JavaScript files, you have a test, and then you have, you know, any server side files as well.
This I'm excited for. That brings in a little bit more opinions into how things are structured. Of course, Caleb mentioned that this is not, you know, de facto. You don't have to use this. This is just another way you could use it.
You can still write things the traditional way, but now you can have views components. These are all your blade and your live wire components. And then you have page level components. And then you have layout components. And this helps to reduce that decision fatigue. You don't have to think about how you should do things and because it's kind of given to you. It's one of the reasons why I like Laravel and I like LiveWire. It's like, hey, I I I want to have my own opinions on how I do things, but I also don't want to think about how things should be structured, too. Can I have a little bit of both?
I kind of talked about this on my Laracon wrap-up video in my hotel room, but this uh lightning bolt emoji was kind of this file prefix for LiveWire components. Uh where you kind of then had this, you know, Livewire Volt counter that has and hosts all of your component structure within that single directory. And this is Unicode. It works across all file systems. You know, even spelt kit, uh Nex.js, JS frameworks like Mojo, they do it.
So, it's just one of those things that this might be the same when it comes out. It might not. I personally like it. I don't care if I have emojis in my in my directory. Then I know, hey, this is this is LiveWire and this is not just a Blade component. Now, here's an interesting part. Uh Caleb kind of talked about how to use PHP 8.4 things to make LiveWire better. These are things that aren't LiveWire or Laravel specific. This is just PHP. Instead of having to use computed properties or let's take JavaScript terms. I like spelt and spelt kit for example.
You have to use dollar sign colon and I think there's a new way in spelt 5 to do this. But you had a dollar sign colon that kind of just has this computed property. It watches for any changes and then it sets those changes based off of those individual variables. But in PHP 8.4 we kind of have that baked in to PHP. we have public setters that say uh
hey I'm going to take this count and whatever that value is in this case for count it prevents that count from going below one so it eliminates this need to hook into the updating function of livewire server or using computed properties for example like if we're using getters it makes that easier so you can say I want this count and then I want to multiply it so then I and just show multiple on you know in the blade component.
So just like in the JavaScript world a lot of people are focused on hey just use the browser just use the primitives that the browser gives you this is just using PHP just use the things that PHP gives you for example this is valid now if you had PHP 8.4 four. You don't have to wait for LiveWire 4 to come out to do uh really any of this. It just works. You can say, "Hey, let's get the cache of a particular thing." And you're not hooking into the mount property or you're not hooking into, I don't know, the render method. It just works.
Now, this is another thing that's kind of just using the things that Laravel, Livewire, Tailwind gives you, and this isn't out until LiveWire 4 comes out.
But you can use this data-loading, which is a loading attribute that is added to an element. Instead of kind of using this wire loading and then you have to use kind of conditional brackets to do conditional CSS, you just use CS Tailwind's CSS uh optional attribute CSS. Now, this one is for everyone in the comments of every single LiveWire video I've ever made that talks about, "Hey, you can't do this because there are no nested components within LiveWire." Well, now there is.
Now, in every single LiveWire component, you can have slots in LiveWire 4 at least where you can talk to those slots to say, "Hey, I want to reference the modal." So when save happens in this modal instead of having necessarily to dispatch and then listen to it you can just say I want to dispatch to this particular modal and then the is live wire slow debate which it is but it's not necessarily live wire's fault.
It's you know writing too much server component logic or it's blade itself rendering everything on the server. It's expensive. That's why single page applications exist because you just render the JavaScript and then it renders everything. It can be faster most of the time. So how can we make this faster within server render components within blade? Well, live wire 4 is going to bring a new compiler blade.
So it optimizes blade at the code folding layer that optimiz it adds an optimization layer so that you can you know fold your code so that it just gives you a clean output. And he kind of went into in the talk and I'll kind of link that talk in the description if you want to go in more depth. It's probably going to come out soon as its own individual video as well. But there's parts of your template, especially within Live Wire and Blade, that don't change, but there's going to be parts that that do change.
So, how can we make that or optimize that better in production? Well, Blaze fixes this. Some of the benchmarks that he showed in the video is 29,000 views rendered over and over. It took about 1.6 seconds. and you have that many views in a typical page most of the time if each loop kind of has its own you know 10 plus views all of a sudden you do have 29,000 in in no time but 100 views rendered in 131
milliseconds the same component it's just folding it so you don't necessarily need all 29,000 views and then last but not least islands now this is this might be controversial but it's actually a great thing to happen because usually Especially if you're just building everything in one component, you don't want to have to separate components and then, you know, send things even if it's slotted things. You don't necessarily want to, you know, have that as a separate component and then have to figure out, okay, how am I, you know, pulling for information or grabbing information.
It's a lot easier if it just all exists on one page, right?
Well, now it can without having to fix this slow unresponsive part and holding up the rest of the page. You can have islands instead. Now, how would you do this? currently. Now, most of the time you probably have a separate component and then you maybe lazy load that component. But again, if you want to talk to it and have to pass information, you don't want to have to do that. You'd rather just have that all exist on the single component instead of having to figure out, okay, how am I passing props and I'm getting props? Am I getting information from this particular, in this case, a chart?
Well, now it becomes its own island that is isolated. It's performance ready and it's responsive.
So the rest of your interface stays snappy. So this island, let's say this takes a long time to maybe grab that information. All of a sudden, um it's not holding up the other pieces of server interaction on the page. This is separate. It's isolated. And that leads into how you can make islands lazy. So in this case, the whole page can load except for one piece, one component. And that's awesome because it's still all in one component.
You see, it's just its own island, but you have additional modifiers. So, not only can you make an island lazy, you can also have an island pull that is again separate. It's isolated from the rest of the component.
So, that way this island can be pulling information without hurting or without kind of locking up the rest of your component if you're wanting to send information, forms, uh, buttons, that kind of thing. As well as being able to intersect and render. So, this makes uh this makes scrolling infinitely easy in LiveWire. I'm finally going to have to redo that video once LiveWire 4 comes out because it's going to be like three lines of code.
And last but not least, testing within LiveWire becomes easier because with browser testing announced by Pest 4 by Nuno Maduro, all of a sudden, testing within LiveWire becomes easier too. you don't have to, I don't know, just wait until you figure out how to interact with the browser because if you're testing LiveWire components, those are, you know, it's JavaScript.
You can't just do the server rendered piece. You have to wait for JavaScript to load. And now just with a simple, hey, let's visit this counter and then we're going to click on this wireclick increment element. And it's as simple as that. And likely it might even be simpler by the time this releases, but that's pretty dang simple. So, I think these announcements, these teasers, this futuristic look into LiveWire 4 does does change things.
It doesn't just change how you look at LiveWire, how you interact with LiveWire, but it changes how a new beginner to PHP to Laravel to LiveWire might see LiveWire. I think it makes it easier. I think it makes it cleaner and I think it makes it harder to write bad Livewire code. And so, I'm I'm excited for this to come out. I'm going to make a full course, a full tutorial when it does come out.