Antiforgery state doesn't always reach interactive components #54533
Labels
area-blazor
Includes: Blazor, Razor Components
bug
This issue describes a behavior which is not expected - a bug.
feature-antiforgery
feature-blazor-state-preservation
Milestone
Repro:
Counter.razor
to include a form__RequestVerificationToken
hidden field (see this using the DOM inspector)__RequestVerificationToken
hidden field. Even if you navigate away and back interactively, it will still be thereThis inconsistency can't be desirable. Whether or not there's an antiforgery token shouldn't depend on which page you first arrived at.
Also note this is not a matter of prerendering. The exact same problem still occurs even if you disable prerendering.
You can work around it by adding
<AntiforgeryToken />
into your layout. The fact that this workaround works suggests that the problem is:<AntiforgeryToken />
on the first WebAssembly render cycle, the persisted antiforgery state just gets discardedI guess we could special-case things for antiforgery by ensuring the WebAssembly renderer always reads that state on the first render. Not sure if an equivalent problem could occur for other persistent component state (perhaps not, because app-specific persistent state would only exist if a component is prerendered to emit it, and then the same component should occur during the WebAssembly startup to collect that state - so maybe this bug is just unique to antiforgery data).
The text was updated successfully, but these errors were encountered: