useSelect crashes blocks if a registered store doesn't implement unsubscribe #27631
Labels
[Package] Data
/packages/data
[Status] In Progress
Tracking issues with work in progress
[Type] Bug
An existing feature does not function as intended
[Type] Regression
Related to a regression in the latest release
Describe the bug
useSelect
might bubble up aTypeError
(unsubscribe
is not a function) that ends up crashing a block in the editor. This happens because it callsunsubscribe
unconditionally without taking into account stores that do not returnunsubscribe
from theirsubscribe
function.This can happen with custom generic stores, where the custom
subscribe
function implementation might not return theunsubscribe
function since, by definition, it's optional (see docs).To reproduce
Steps to reproduce the behavior:
2.5.3
tag;yarn && yarn build
;v9.5.1
tag, build it;.wp-env.json
: https://gist.github.com/fullofcaffeine/aa4c76e5fad53f3ac52366bff3a85e44;wp-env
installed globally;wp-env start .
;This seems to happen with other blocks too. I smoke-tested columns, quote, list, and they all crashed.
Expected behavior
Blocks don't crash and work when the user adds/sets them up if a generic wp-data store that doesn't implement an
unsubscribe
function is registered.Screencast
Editor version (please complete the following information):
5.5.3
gutenberg plugin
9.5.1
Desktop (please complete the following information):
84.0b8 (64-bit)
and Chrome87.0.4280.66 (Official Build) (64-bit)
Additional context
The text was updated successfully, but these errors were encountered: