Render components via view - #213
Conversation
Benchmark Result: Default
Median of 10 attempts, 5000 iterations x 10 rounds, 47.61s total To run a specific benchmark, comment |
|
@ghabriel25, saw you were looking at this issue too, wanna take a stab at it? I would prefer this approach I outlined here however there are few issues with it and I don't have the capacity to pursue this right now so if you do it would be much appreciated, if not that's also fine.
1: I don't fully understand what is causing the issue or how to fix it 2 & 3: this is an issue of having the source in the compiled file twice, these directives have a side-effect so duplicating the source is probably off the table entirely. I had an LLM suggest hacking into the directive compiler and changing how these directives are rendered but I found that super gross. I'm thinking instead of duplicating the source we could simply define the function upfront and then if we detect that the file is rendered via 4: This should be pretty easy to solve by using If all fails, we could re-explore your approach, the only issue I had there was all the regexes inside the new Of course the approach in this PR is more desirable as it solves the underlying issue of not being able to render Blaze-compiled components via If there are issues with that too, or if you don't have the capacity to look into this I'll just close this along with the issue and we will just keep it as a limitation as it is for now. Let me know, thanks! |
|
Hi @ganyicz rather than duplicates the compiled template body (one copy for the <?php
// define function up here
// call the function if the file is required via `view()`
if (isset($__path) && realpath($__path) === realpath(__FILE__)) {
foo(
$__blaze ?? app('blaze.runtime'),
get_defined_vars(),
[], [], [], null
);
}
?> |
|
Yes that's exactly what I suggested but have a look at all the other points too please |
|
Also @ghabriel25, no rush, think it through. This could be a significant change and I want to get this right. As I've mentioned I don't have the capacity for it right now and I just thought you might want to give it a try since you've already attempted it with the other PR. But I want to make sure we can address all the issues really well and if we can't, or you don't feel like it, that's totally fine, just let me know and we'll table it for now and revisit later. It's already a documented limitation anyway. |
|
Yeah. I wanna give it a try but dont expect too much as you can see my previous attempt really too narrow. I'll test each one of issues you mentioned above |
|
@ghabriel25 Awesome, thanks! And no worries, take a good look through my notes above, I think your narrower approach could be acceptable too if this one fails, when you've explored all the options, open a new PR with what you think is the best approach to solving this (if there even is one). Either way, no pressure. Appreciate your help! |
The scenario
Rendering a Blaze component via
view()produces no output.This particularly affects class-based components as their views are often compiled by Blaze based on path.
To fix this, the user needs to exclude class-based components like so:
However, this is unintuitive.
The problem
Compiled Blaze components only contain a function definition and do not produce any output when required:
The solution
Include both rendering paths in the compiled file, using
$__pathto detect when Laravel is rendering it as a view:The
$__pathvariable comes fromFile::getRequire()that's used by Blade to render file contents:Fixes #210