-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2.0.6 upgrade causes crash when rendering a view with a flux checkbox component to a variable before output to a file #1330
Comments
@colinmackinlay While simplified code snippets are good, this one isn't complete enough to be copy/pasteable to test/reproduce the issue. Can you provide one that is? |
Thanks for quick response @jeffchown . Perhaps I wasn't clear about simplifying - I've just taken all my app specific stuff out and tested with this code as the entire content of a view. The code will render in a browser so there's no point in creating a volt component to show it. The error only happens when I call I've narrowed the change that causes the issue to #1308 . If I edit the props in I don't explicitly render the error part of the flux component but it must be being triggered by some part of the way Laravel renders it to data rather than to a browser. If I deconstruct checkbox so that it has no errors like this then the error goes away:
So I've found a workaround but it feels a bit of a kludge. The problemn is probably somewher within |
@colinmackinlay Thanks for the further detail. Interesting. Sounds like @joshhanley might have some insight(s) given his work on that nested attributes validation/error PR. |
@colinmackinlay thanks for reporting! I'm unable to replicate the issue with the code provided. Can you provide a repo that demonstrates the issue so we can investigate it? Thanks! |
Thanks @joshhanley - I'll have a go at producing a clean repo to narrow it down. I'll get back to you when I've done that |
@colinmackinlay great, thanks! |
Here's a repository @joshhanley : https://github.com/colinmackinlay/flux
|
@colinmackinlay thanks for that! So I can replicate the issue and I can see why the changes we have made are now triggering the error for you. But I also wanted to know why the error wasn't thrown previously and why it's thrown at all. The reason is previously we only had this, in the errors component: $message ??= $name ? $errors->first($name) : null; So as you don't have a name parameter defined on your checkbox component, it's never calling If I use Flux before the latest update and add a name attribute to the checkbox in your test app, it throws the same error. ![]() So then I experimented with removing the Flux component all together and using trying to render a view that might have errors in them, like you would normally do with Blade, by outputting It turns out there is an issue with testing Blade views that have been loaded manually, as you can see by this Laracasts discussion https://laracasts.com/discuss/channels/testing/undefined-variable-errors-when-testing-a-view One could argue that this is more of a Laravel issue than a Flux one, as this could happen anywhere that you might use But that being said, we can fix it in Flux for this specific scenario. Recently we added this, which is what is causing if ((is_null($message) || $message === '') && filter_var($nested, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== false) {
$message = $errors->first($name . '.*');
} So all we need to do is add a check for if ($name && (is_null($message) || $message === '') && filter_var($nested, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== false) {
$message = $errors->first($name . '.*');
} I've submitted a PR with a fix. |
Flux version
2.0.6
Livewire version
3.6.2
Tailwind version
4.0.7
Browser and Operating System
Edge WIndows
What is the problem?
Upgrading flux to 2.0.6 from 2.0.5 has introduced an issue when I render a view containing checkboxes using
Illuminate\Contracts\View\Factory
for output to a pdf file.The error I get is 'Illuminate\View\ViewException: Undefined variable $errors (View: .....\vendor\livewire\flux\stubs\resources\views\flux\error.blade.php)'
I can trace this back to this code:
$html = view($view, $data)->render();
whenIlluminate\Contracts\View\Factory
is being called using theview()
helper method.My view contains this code (simplified from actual to remove variables):
If everything else in the review is removed the error still occurs with this simplified code.
If this last bit of code is removed there is no error.
If I revert to flux 2.0.5 there is no error
Code snippets
How do you expect it to work?
If this code is contained in a view and the view is rendered to a file then no error should occur - just as was the case in flux 2.0.5
Please confirm (incomplete submissions will not be addressed)
The text was updated successfully, but these errors were encountered: