Fix optimize class-based view rendered as empty output - #212
Closed
ghabriel25 wants to merge 2 commits into
Closed
Conversation
Contributor
Benchmark Result: Default
Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 25.91s total To run a specific benchmark, comment |
Contributor
Author
|
Closing in favor #213 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevents
Blaze::optimize()->in()from wrapping views that belong to class-based components, which previously caused those components to render as empty output with no exception.Problem
When a directory is optimized via
Blaze::optimize()->in(...), every Blade file under that path is compiled and wrapped into a Blaze function. Class-based components do not go through the Blaze runtime — they render viaComponent::render()→ the view engine →PhpEngine::evaluatePath(), which simplyrequires the compiled file and captures its output.The Blaze wrapper only defines a function; nothing calls it. Result:
This is especially easy to hit because Laravel’s
make:component(class-based) writes the view intoresources/views/components— the same path the README uses as the example for directory optimization.Solution
Skip the Blaze wrap when the view path is the conventional view of a class-based component.
BladeService::isClassBasedComponentView(string $path): bool/components/segmentforms/input.blade.php→forms.input)hasClassBasedComponent()(same resolution order as Laravel’sComponentTagCompiler)Wrap guard in
BlazeManager::compile()(and the folding compile path for consistency):The class-based check is absolute: even an explicit
@blazeon a class-based view is ignored. Class-based components remain unsupported; this only stops poisoning their normal Blade path.Anonymous components in the same optimized directory are unaffected and still get compiled/wrapped as before.
Changes
src/BladeService.php— addisClassBasedComponentView()src/BlazeManager.php— skip wrap for class-based component views incompile()andcompileForFolding()tests/BladeServiceTest.php— unit tests for detection (class-based vs anonymous, nested names)tests/BlazeManagerTest.php— integration test: optimize directory containing a class-based view and assert correct HTMLAlertcomponent + fixture updated to a real class-based component (render()returnsview('components.alert'))Fixes: #210