Add safer checks in ExtraDataMixin's logic to check extraData support.

Review Request #14407 — Created April 28, 2025 and submitted — Latest diff uploaded

Information

Review Board
release-7.1.x

Reviewers

ExtraDataMixin has a series of checks to determine if it should
set this.extraData. When calling set(), it makes a determination
based on the attributes passed in and the current object. This doesn't
always do the right thing, though.

If attributes are passed in and this.extraData is not set, then we
fail when trying to call a method on it.

Along with that, the method used to check this.extraData was a
presence check in the property, which isn't as safe as a truthiness
check. While fine in practice, this issue was encountered when changing
Babel's TypeScript options to enable allowDeclaredFields, which
resulted in extraData being explicitly set to undefined.

The safer check and the asserts should help catch any confusing issues
in the future.

Unit tests pass.

Tested with the failure condition and saw the more useful error.

Diff Revision 1 (Latest)

Commits

First Last Summary ID Author
Add safer checks in ExtraDataMixin's logic to check extraData support.
`ExtraDataMixin` has a series of checks to determine if it should set `this.extraData`. When calling `set()`, it makes a determination based on the attributes passed in and the current object. This doesn't always do the right thing, though. If attributes are passed in and `this.extraData` is not set, then we fail when trying to call a method on it. Along with that, the method used to check `this.extraData` was a presence check in the property, which isn't as safe as a truthiness check. While fine in practice, this issue was encountered when changing Babel's TypeScript options to enable `allowDeclaredFields`, which resulted in `extraData` being explicitly set to `undefined`. The safer check and the asserts should help catch any confusing issues in the future.
158626d1242bd138976d6d69fd9bb12b89e5d7d7 Christian Hammond
reviewboard/static/rb/js/common/models/extraDataMixin.ts
Loading...