Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
fix: collection config deep merge during sanitization causing unpredictable behavior (#11524)
Deep‐merging the collection config defaults during sanitization causes all collection fields to end up with different object references. This is not only slow, but can also lead to unpredictable behavior: mutations made before collection sanitization are reflected in the field config, while mutations made afterward, using the same object reference, are not reflected in the collection’s field config. Specifically, the following happened: 1. A Block was defined in the module scope. 2. It was then added to both a collection’s blocks field and the config.blocks property. 3. Rich text sanitization promises for config.blocks were collected. 4. The collection config was sanitized. 5. The config.blocks sanitization promises were awaited. 6. Rich text fields were sanitized in config.blocks, but ended up not being sanitized in the collection config referencing the same block, because the object reference held by the promise callback no longer matched the collection config’s object reference. The collection config block did not create its own rich text sanitization promise, as `_sanitized: true` was set on the block during the earlier config.blocks sanitization, which skipped it. Our config defaults pattern was brittle in general. It’s easy to misuse object spreading or to mutate the config defaults later when you intended only to mutate the payload or collection config. Our current approach was vulnerable to this because it retained some object references from the config defaults. This PR introduces reliable merge functions that are faster and ensure no object references are shared with defaults that reside in the module scope.
A
Alessio Gravili committed
5adb764b08f5782e700d8c9ad82b0516558f3a79
Parent: 56dec13
Committed by GitHub <noreply@github.com>
on 3/4/2025, 9:02:26 PM