Wizard issue with missing $statePath

I have a livewire component wizard that seems to be hitting intermittent issues for a very few users, I'm unable to recreate the issue. We're running the site on a load balancer, so it might just be a server or two playing up. I'm saving the form data to individual properties, rather than using $statePath, but occasionally the wizard seems to crash when moving to the next step production.ERROR: Filament\Forms\Components\Wizard::Filament\Forms\Components{closure}(): Argument #2 ($statePath) must be of type string, null given, Which seems to be related to:
$this->registerListeners([
'wizard::nextStep' => [
function (Wizard $component, string $statePath, int $currentStepIndex): void {
$this->registerListeners([
'wizard::nextStep' => [
function (Wizard $component, string $statePath, int $currentStepIndex): void {
from Wizard.php Any idea why it works 99% of the time, but occasionally falls over? We're on php 8.2 Thanks!
2 Replies
LeandroFerreira
LeandroFerreira4mo ago
You could try to create a custom component extending the Wizard and change it to null|string $statePath If it works, probably this is a bug
tomb8091
tomb8091OP4mo ago
Ah! good idea, I'll try that - weird that it's so difficult to recreate the bug
$this->registerListeners([
'wizard::nextStep' => [
function (Wizard $component, null|string $statePath, int $currentStepIndex): void {

//Tom added this return, temporary fix
return;


if ($statePath !== $component->getStatePath()) {
return;
}

if (! $component->isSkippable()) {
/** @var Step $currentStep */
$currentStep = array_values(
$component
->getChildComponentContainer()
->getComponents()
)[$currentStepIndex];

try {
$currentStep->callBeforeValidation();
$currentStep->getChildComponentContainer()->validate();
$currentStep->callAfterValidation();
} catch (Halt $exception) {
return;
}
}

/** @var LivewireComponent $livewire */
$livewire = $component->getLivewire();
$livewire->dispatch('next-wizard-step', statePath: $statePath);
$this->registerListeners([
'wizard::nextStep' => [
function (Wizard $component, null|string $statePath, int $currentStepIndex): void {

//Tom added this return, temporary fix
return;


if ($statePath !== $component->getStatePath()) {
return;
}

if (! $component->isSkippable()) {
/** @var Step $currentStep */
$currentStep = array_values(
$component
->getChildComponentContainer()
->getComponents()
)[$currentStepIndex];

try {
$currentStep->callBeforeValidation();
$currentStep->getChildComponentContainer()->validate();
$currentStep->callAfterValidation();
} catch (Halt $exception) {
return;
}
}

/** @var LivewireComponent $livewire */
$livewire = $component->getLivewire();
$livewire->dispatch('next-wizard-step', statePath: $statePath);
I think there must be some kind of bug, by type hinting null, the function seems to return false for if ($statePath !== $component->getStatePath()) { return; } Then it runs the rest of the logic and all my conditionally hidden fields aren't showing until the final step. If I simply return at the top, the wizard works perfectly, at least it appears to. Is this safe to do?
Want results from more Discord servers?
Add your server