[12.x] Add @includeIsolated directive for isolated Blade includes#58311
[12.x] Add @includeIsolated directive for isolated Blade includes#58311taylorotwell merged 3 commits intolaravel:12.xfrom
@includeIsolated directive for isolated Blade includes#58311Conversation
@includeScoped directive for isolated Blade includes@includeIsolated directive for isolated Blade includes
|
this is great, @KennedyTedesco!!! Thank you so much! |
|
love the isolation, and it's the reason I've basically only used components in our apps for many years. when you talk about overhead on the components, are you talking about performance impacts? do these hits still exist when caching views? |
|
@browner12 Sorry, just saw your message now. The "overhead" (not a big thing, tbh) with components is primarily: 1 - Class instantiation (for class-based components): this still happens at runtime even with cached views Honestly, the performance aspect is secondary for me. The main benefit is having a middle ground: I just want to include a partial, not render a component, but still get the isolation. Now that's possible. |
|
Nice! Though I have overridden blade compiler to disable it by default for everything, might think about using this instead. I find the original behavior bringing many unexpected and unwanted results with couple level deep includes, especially with forms. |
This PR introduces a new
@includeIsolatedBlade directive that includes a view without inheriting the parent scope's variables.I work in a codebase where we use
<x-component>for reusable components and@component()for partials (because we like variable isolation). However,@component()brings overhead we don't need: slot management, the opening/closing tag ceremony, and component lifecycle logic.@includeIsolatedwould give us the best of both worlds: the simplicity of@includewith the isolation of@component.This PR is another shot of: #45616
Motivation
Currently,
@includepasses all parent scope variables viaget_defined_vars():This implicit inheritance can lead to:
The recommended workaround is Blade components (
<x-partials.hero />), but components come with overhead(slots, validation, class resolution) that isn't always needed for simple partials.
Proposed Solution
@includeIsolated()provides explicit-only data passing where "explicit > implicit":Benefits:
@component(no slot/component machinery)@includeIf,@includeWhen,@includeFirstpatterns