Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LvckyAPI's avatar

Exception while rendering Blade in a component results in death of laravel

Reference: https://github.com/LvckyAPI/filament-debug

I have a form in which I can enter code (HTML with Blade).

Next to it is a field that is supposed to render the whole thing live.

If I enter something like {{fake()}}, the rendering dies, of course, and everything else crashes with a big error screen.

The exception cannot be caught.

-> My initial solution was to use concurrency.

Unfortunately, this resulted in even more problems. Serialization fails, languages are no longer passed.

My goal is to render three fields. If an error occurs in one rendering process, it should be caught and displayed in the field without affecting the rendering of the others.

Here is my code for LivePreview currently using concurrency:

Translated with DeepL.com (free version)

// preview.blade.php
@php
    $previewEncoded = base64_encode($preview);
    $plainEncoded = base64_encode($plain ?? '');
@endphp

<div style="height: 100%; display: flex; flex-direction: column; gap: 2px">
    <h1 style="flex: none">{!! $renderedSubject !!}</h1>
    <hr style="flex: none"/>

    <iframe style="flex: 2; min-height: 100vh; width: 572px"
            src="data:text/html;charset=utf-8;base64,{{ $previewEncoded }}"></iframe>

    @if(!empty($plain))
        <hr style="flex: none"/>
        <iframe style="flex: 1; min-height: 100vh; width: 572px"
                src="data:text/plain;charset=utf-8;base64,{{ $plainEncoded }}"></iframe>
    @endif
</div>

// filament form
                            CodeEditor::make('subject')
                                ->language(CodeEditor\Enums\Language::Php)
                                ->label(__('message.field.subject'))
                                ->hintIcon(Heroicon::OutlinedQuestionMarkCircle, __('message.field.subject_hint'))
                                ->default(null)
                                ->live(debounce: 1000)
                                ->columnSpanFull(),

                          
                            CodeEditor::make('html')
                                ->label(__('message.field.html'))
                                ->default(null)
                                ->language(CodeEditor\Enums\Language::Php)
                                ->live(debounce: 1000)
                                ->visible(fn(Get $get) => $get('type')->allowedTextTypes()->contains(MessageTextTypeEnum::HTML)),

                            MessagePreview::make('__preview')
                                ->label(__('message.field.preview'))
                                ->visibleOn(['edit', 'view']),

//message preview compoennt
<?php

namespace App\Filament\Forms\Components;

use Filament\Forms\Components\ViewField;

class MessagePreview extends ViewField
{
    protected string $view = 'filament.forms.components.message-preview';
}
<x-dynamic-component
    :component="$getFieldWrapperView()"
    :field="$field"
>
    <div
        x-data="{ state: $wire.$entangle(@js($getStatePath())).defer }"
        {{ $getExtraAttributeBag() }}>
        <x-message-live-preview
            @viteReactRefresh
            :message="$record"
            :content="$get('html')"
            :subject="$get('subject')"
            :plainText="$get('plain_text')"
        />
    </div>
</x-dynamic-component>

Can anyone provide me better solution without this hack fuck and problems

0 likes
0 replies

Please or to participate in this conversation.