From 70f6f1924509b5a2389ac48d13e3eb00fae9a744 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Wed, 16 Mar 2022 04:13:21 -0700 Subject: [PATCH] Core Data: Check for presence of entity config before testing plural form. (#39476) When auto-generating method names for various entities in the data system we want to use manually-listed plural forms if they exist. Previously, however, we've been assuming that when we search for an entity's config that it exists. While this probably hasn't been a real source of bugs it does present an opportunity for an invalid-type runtime exception. In this patch we're verifying that the config exists before we access the `plural` property, eliminating the opportunity for the rutnime crash. --- packages/core-data/src/entities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index e0332a27b562ab..be2186d9353862 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -297,7 +297,7 @@ export const getMethodName = ( const nameSuffix = upperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' ); const suffix = - usePlural && entityConfig.plural + usePlural && entityConfig?.plural ? upperFirst( camelCase( entityConfig.plural ) ) : nameSuffix; return `${ prefix }${ kindPrefix }${ suffix }`;