Skip to content

refactor: Replace isDefined spreads with an omitUndefined helper - #1292

Merged
kylebarron merged 2 commits into
mainfrom
kyle/omit-undefined
Sep 30, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/omit-undefined

Conversation

@kylebarron

@kylebarron kylebarron commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

Closes #1196

Before, the frontend passed each optional prop to deck.gl with its own conditional spread:

...(isDefined(this.widthScale) && { widthScale: this.widthScale }),
...(isDefined(this.getFillColor) && {
  getFillColor: accessColorData(this.getFillColor, batchIndex),
}),

This PR adds an omitUndefined helper to src/util.ts, like the one in developmentseed/deck.gl-raster#557. Each layer, view or control now passes its optional props through a single call:

...omitUndefined({
  widthScale: this.widthScale,
  getFillColor: accessColorData(this.getFillColor, batchIndex),
}),

Props have to be left out, not passed as undefined, because deck.gl copies an explicit undefined over a layer's default. The helper now handles that in one place.

What changed

  • omitUndefined drops both null and undefined, matching the old isDefined check. Unset traits arrive from Python as null, so behavior doesn't change.
  • accessColorData and accessFloatData return undefined for an unset accessor. Vector accessors use ?.data[batchIndex]. This lets accessor props go through omitUndefined too.
  • The flyTo options in renderers/overlay.tsx used != null spreads and now use the helper as well.
  • extensionProps, prepareTexture and the DataFilterExtension were the last callers of isDefined. They are rewritten, and isDefined is removed.
  • Adds tests for omitUndefined and for the accessor helpers with unset input.

The Number.isFinite spreads in sanitizeViewState stay as they are, because they also drop NaN and Infinity.

Checks

  • pnpm test passes.
  • biome check is clean.
  • pnpm build succeeds.
  • tsc --noEmit shows the same 7 errors as main and no new ones.

🤖 Written by Claude Code

Replace the long runs of `...(isDefined(x) && { x })` spreads with a
single `...omitUndefined({ ... })` per group. deck.gl copies an explicit
`undefined` over a layer's default props, so unset props must be left
out rather than passed as `undefined`; the helper does that in one place.

Spreads that transform the value (e.g. `accessColorData(...)`) keep the
explicit `isDefined` check. Behavior is unchanged: the helper drops the
same `null` and `undefined` values that `isDefined` did.

Closes #1196

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/model/layer/point-cloud.ts Resolved
Comment thread src/model/layer/polygon.ts Resolved
…ned`

`accessColorData` and `accessFloatData` now return `undefined` for an
unset accessor, and vector accessors use `?.`, so the accessor props can
go through `omitUndefined` like every other optional prop. The same goes
for the flyTo options in the overlay renderer, which used `!= null`
spreads.

With no conditional spreads left, `isDefined` has no callers and is
removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kylebarron kylebarron changed the title refactor: Forward optional props with an omitUndefined helper refactor: Replace isDefined spreads with an omitUndefined helper Sep 30, 2026
@kylebarron
kylebarron enabled auto-merge (squash) September 30, 2026 00:15
@kylebarron
kylebarron merged commit 04cbca6 into main Sep 30, 2026
6 checks passed
@kylebarron
kylebarron deleted the kyle/omit-undefined branch September 30, 2026 00:19
kylebarron added a commit that referenced this pull request Sep 30, 2026
> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

Fixes the failing `Python test` workflow on `main`.

The `normalize-notebook-kernelspec` pre-commit hook added in #1254
requires every notebook's kernelspec to be exactly `{"display_name":
"Python 3 (ipykernel)", "language": "python", "name": "python3"}`.
`examples/geohash-layer.ipynb` (added in #1242) has `"display_name":
"Python 3"`, so the hook rewrites it and fails the `tests (3.11)` job,
which is the job that runs pre-commit.

#1254's PR CI passed because its base branch was older than #1242, so
the geohash notebook wasn't there to check. The two changes only met
after both merged.

This PR is the output of running the hook itself: a one-line change to
`display_name`. It's the only notebook in the repo that didn't already
match.

`uv run pre-commit run --all-files` passes locally with this change.

The earlier failure on the #1292 push was a separate, transient network
error (`uv sync` couldn't download the `pyogrio` wheel from PyPI) and
needs no change.

🤖 Written by [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleaner omitUndefined

1 participant