Skip to content

Conversation

@iotron
Copy link
Contributor

@iotron iotron commented Dec 16, 2025

Summary

This PR fixes the TypeError: Argument #2 ($rawState) must be of type ?array, string given error that occurs when saving a form that contains a RichEditor field in HTML mode (not using ->json()) without editing that field.

Related issues:

Problem

When a RichEditor stores content as HTML (the default mode), the beforeStateDehydrated callback registered in setUp() expects ?array $rawState. However, when the form is saved without editing the RichEditor field:

  1. callAfterStateUpdated() is NOT called (since the field wasn't updated)
  2. callBeforeStateDehydrated() IS called (as part of the form save process)
  3. getRawState() returns the HTML string from the database
  4. The callback receives a string instead of an array, causing the type error

The existing fix in PR #17762 added state normalization to callAfterStateUpdated(), which only runs when the RichEditor field itself is edited. This doesn't cover the case where other fields are edited but the RichEditor is left untouched.

Solution

Add the same state normalization logic to callBeforeStateDehydrated(), which runs during every form save regardless of which fields were edited. This ensures the raw state is converted to the expected array format before the beforeStateDehydrated callback is invoked.

Test Case

  1. Create a model with a RichEditor field storing HTML (not using ->json() mode)
  2. Save some HTML content to the field
  3. Edit ANY other field in the form (not the RichEditor)
  4. Save the form
  5. Without this fix: TypeError is thrown
  6. With this fix: Form saves successfully

@github-project-automation github-project-automation bot moved this to Todo in Roadmap Dec 16, 2025
@danharrin danharrin added bug Something isn't working pending review labels Dec 17, 2025
@danharrin danharrin added this to the v4 milestone Dec 17, 2025
@maarten-mald-digital
Copy link

Looking good! Waiting for this fix

@danharrin
Copy link
Member

Can you create a reproduction repository for this issue please? I don't understand why the state would be a string in the first place: the state cast should convert it to an array when the form is filled with the existing string, even if JSON mode is not being used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants