[BUG] Previous step state is getting reset to the initialState() values in later steps #143
Unanswered
NankoPrinzhorn
asked this question in
Q&A
Replies: 2 comments 2 replies
|
We have the same issue. |
0 replies
|
I haven't verified if the root cause is correct, as I'm a bit under the weather and my head hurts, but according to Claude it's because of changes in Livewire 4's JS methods how they handle dotted values. Instead of it using This trait was cooked up by Claude and goes in the wizard itself. If it works I can create a PR. trait NestsStepState
{
public function setStepState(string $step, array $state = []): void
{
if (! $this->stepNames()->contains($step)) {
throw StepDoesNotExist::doesNotHaveState($step);
}
Arr::set($this->allStepState, $step, $state);
}
public function getCurrentStepState(?string $step = null): array
{
$stepName = $step ?? $this->currentStepName;
$stepName = class_exists($stepName)
? $this->componentName($stepName)
: $stepName;
throw_if(
! $this->stepNames()->contains($stepName),
StepDoesNotExist::stepNotFound($stepName)
);
$allStepsState = [];
foreach ($this->stepNames() as $name) {
$data = Arr::get($this->allStepState, $name);
if (is_array($data)) {
$allStepsState[$name] = $data;
}
}
return array_merge(
Arr::get($this->allStepState, $stepName, []),
[
'allStepNames' => $this->stepNames()->toArray(),
'allStepsState' => $allStepsState,
'stateClassName' => $this->stateClass(),
'wizardClassName' => static::class,
],
);
}
} |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi all, I was unable to create a issue, so here I am in the Q&A section
We have just upgraded from Livewire "^v3.6" to "^v4" and also patched this Laravel Wizard package from "^v2.4" to "^3.1".
Since this upgrade we are experiencing issues with the wizard. It seems that in later steps, the state of earlier steps are getting reset to the initial state values defined in the wizard component. It could be that the implementation is incorrect, but the scenario has worked before we upgraded.
Reproduction
Repository:
https://github.com/NankoPrinzhorn/LaravelWizardInitialStateIssue
Demo screen recording:
Screen.Recording.2026-02-18.at.11.58.37.mov
Code:
Scenario
In Step1, two values are defined:
Both Step2 and Step3 dump the data returned from the custom state method:
$this->state()->getStep1Data().Expected behaviour
It is expected that the data entered in Step1, is persistent in all following steps.
Actual behaviour
Undefined array key "stepText"Weird Observation
After the error is shown to the user, if the user would click the error away and manually goes back to the first step. The whole process is working again as expected without errors. See below
Screen.Recording.2026-02-18.at.12.18.45.mov
All reactions