Skip to content

fix(hooks): skip writing props the consumer never provided - #1074

Open
rpinckne wants to merge 1 commit into
visgl:mainfrom
rpinckne:fix/prop-binding-unprovided
Open

rpinckne wants to merge 1 commit into
visgl:mainfrom
rpinckne:fix/prop-binding-unprovided

Conversation

@rpinckne

Copy link
Copy Markdown

Summary

usePropBinding assigns every bound prop as soon as the element exists, including the props the consumer left out, so each custom element receives a burst of undefined writes on mount. Two effects of that on the Maps API:

Change

A prop is written only once it has a value. After that, a later undefined still clears it (removing a prop keeps working), and a fresh object starts untouched even if the hook wrote to a previous one.

This is the general form of the guard #1066 adds inside useAdvancedMarkerAnchoring; it covers every usePropBinding call site in the 3D components, Marker3D, and Popover.

Tests

  • src/hooks/__tests__/use-prop-binding.test.tsx: unprovided prop never written (no own property), provided values including null written, value-then-undefined clears, and a new object is left untouched.
  • npm test: 23 suites / 194 tests pass, tsc --project tsconfig.test.json, eslint and prettier clean.

usePropBinding assigned every bound prop on mount, including the ones the consumer left out, so each custom element received a burst of `undefined` writes. On the Maps API that clobbers defaults the element set up for itself (the class of visgl#867) and, for deprecated or channel-gated properties such as `coordinates`, `innerCoordinates`, `outerCoordinates`, and `autofitsCamera` on the 3D elements, logs a console warning for a prop the consumer never wrote, once per element.

A prop is now written only once it has a value; after that, a later `undefined` still clears it, and a fresh object starts untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant