Skip to content

Remove special handling of raw / rendered attributes from core-data #34449

Closed as not planned

Description

@adamziel

What problem does this address?

The REST API returns the following data shape for posts:

{
  id: 15,
  content: { raw: "abc", rendered: "<div>abc</div>" }
}

core-data has some special logic in place to flatten that into { id: 15, content: "abc" }. It lives in getRawEntityRecord and saveEntityRecord.

Hiding the presence of .raw saves us a few characters here and there (.raw and { raw: value }) but it creates consistency problems across core-data:

What is your proposed solution?

Do not flatten the data at all. Embrace the nested data in raw / rendered attributes and refer to them explicitly.

@youknowriad suggested the following:

maybe an ideal scenario WP API is just an adapter for core-data to the WordPress API, and core-data's object structures have actual meaningful formats defined by the package itself (and potentially be inspired by WP's format).

Questions to discuss:

  • What kind of format we want to expose to core-data's consumers?
  • How do we edit core-data's entities? editEntity({ title: { raw: "something" } }) or just. editEntity({ title: 'something' }) ?
  • What happens to the "rendered" property when the "raw" changes in the edited entity? should it return an error, match raw (we can't since it's generated server side), something else...

Once we have a PR in place, we should also check for performance regressions (there may be a performance impact caused by switching from shallow object spread to deep object merge).

Activity

  1. changed the title [-]Move post-specific logic out of core-data package[/-] [+]Remove special handling of `raw` / `rendered` attributes from core-data[/+] on Sep 1, 2021
  2. added
    [Type] Enhancement
    on Aug 18, 2023
  3. ellatrix commented on Nov 4, 2026

    @ellatrix
    Member

    Tested on trunk: getEntityRecord keeps { raw, rendered }, while getEditedEntityRecord returns the raw string for the fields listed in the entity's rawAttributes. Entities without rawAttributes, like root/site, are not flattened.

    Raw and flattened values

    Two of the problems listed here were fixed: #34388 added rawAttributes so only the listed post fields are flattened (not other entities), and #34502 removed the raw extraction from saveEntityRecord.

    The flattening itself is on purpose. The code says edits are raw values, so records are returned the same way to make comparing and joining them with edits easy. Removing it would change what getEditedEntityRecord returns and what editEntityRecord takes, which every plugin that edits a title or content relies on. Closing as not planned.

    Partly automated with help from Claude.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Package] Core data[Type] Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions