Fathi
Fathi

Reputation: 11

Laravel Filament is slow

I'm facing with slow performance where when i input on the pay TextInput, it is so delayed, so when i typed fast in the input for example: i input 1000000, it will return to 100

TextInput::make('total_fine')
                            ->required()
                            ->readOnly()
                            ->numeric()
                            ->afterStateUpdated(function ($state, Get $get, Set $set) {
                                $change = (int)$get('pay') - (int)$state;

                                $set('change', $change);
                            })
                            ->reactive()
                            ->default(0),

                        TextInput::make('pay')
                        ->label('Pay')
                            ->required()
                            ->numeric()
                            ->afterStateUpdated(function ($state, Get $get, Set $set) {
                                $change = $state - $get('total_fine');

                                $set('change', $change);
                            })
                            ->reactive()
                            ->default(0)
                            ->rules([
                                fn (Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) {
                                    $change = (int)$value - (int)$get('total_fine');

                                    if ($change < 0) {
                                        $fail("The money is insufficent!");
                                    }
                                },
                            ]),

                        TextInput::make('change')
                            ->required()
                            ->readOnly()
                            ->numeric()
                            ->reactive()
                            ->default(0),

this is my Components that i'm using

Upvotes: 1

Views: 1403

Answers (1)

W Kristianto
W Kristianto

Reputation: 9303

Debouncing ensures that the state update function is not called on every keystroke, but rather after the user has stopped typing for a specified duration. This can significantly reduce the number of updates and improve performance.

https://filamentphp.com/docs/3.x/forms/advanced#debouncing-reactive-fields

Upvotes: 1

Related Questions