[Tech Debt] Audit and fix usage of useOpenSearchDashboards().services
#3392
Labels
good first issue
Good for newcomers
help wanted
Community development is encouraged
technical debt
If not paid, jeapardizes long-term success and maintainability of the repository.
typescript
There seems to be quite a bit of the antipattern where a component calls
useOpenSearchDashboards()
as a convenience hook to fetch any core service it may want to use. But the problem is that not all the services are necessarily defined. This leads to bugs like #3327, where the entire component rendering crashes in cases where thelinkService
is not yet defined.There are also other antipatterns such as
OpenSearch-Dashboards/src/plugins/vis_type_vega/public/components/vega_help_menu.tsx
Line 43 in 5b8a378
(the optional chaining prevents unhandled exceptions, but it means the link href will be
undefined
if the service isn't found)Or
OpenSearch-Dashboards/examples/bfetch_explorer/public/hooks/use_deps.ts
Line 34 in 5b8a378
(the type casting assures the typescript compiler that the
explorer
service will be defined, while the hook makes no such guaranteesOr
OpenSearch-Dashboards/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx
Line 57 in 5b8a378
(which incorrectly uses the non-null assertion operator)
From my quick glance, it does appear to be handled correctly in other components, such as
OpenSearch-Dashboards/src/plugins/opensearch_dashboards_react/public/ui_settings/use_ui_setting.ts
Lines 70 to 74 in 5b8a378
The goals of this issue are to:
The text was updated successfully, but these errors were encountered: