Skip to content

Commit

Permalink
[RNMobile] Prevent unnecessary re-renders of RichText component due t…
Browse files Browse the repository at this point in the history
…o color palettes prop (#40615)
  • Loading branch information
fluiddot authored and SiobhyB committed Apr 26, 2022
1 parent 5651a1e commit cc03315
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/rich-text/src/component/index.native.js
Expand Up @@ -51,6 +51,15 @@ const unescapeSpaces = ( text ) => {
return text.replace( / | /gi, ' ' );
};

// The flattened color palettes array is memoized to ensure that the same array instance is
// returned for the colors palettes. This value might be used as a prop, so having the same
// instance will prevent unnecessary re-renders of the RichText component.
const flatColorPalettes = memize( ( colorsPalettes ) => [
...( colorsPalettes?.theme || [] ),
...( colorsPalettes?.custom || [] ),
...( colorsPalettes?.default || [] ),
] );

const gutenbergFormatNamesToAztec = {
'core/bold': 'bold',
'core/italic': 'italic',
Expand Down Expand Up @@ -1260,14 +1269,10 @@ export default compose( [

const settings = getSettings();
const baseGlobalStyles = settings?.__experimentalGlobalStylesBaseStyles;
const colorsPalettes = settings?.__experimentalFeatures?.color?.palette;
const allColorsPalette = [
...( colorsPalettes?.theme || [] ),
...( colorsPalettes?.custom || [] ),
...( colorsPalettes?.default || [] ),
];
const colorPalette = colorsPalettes
? allColorsPalette

const colorPalettes = settings?.__experimentalFeatures?.color?.palette;
const colorPalette = colorPalettes
? flatColorPalettes( colorPalettes )
: settings?.colors;

return {
Expand Down

0 comments on commit cc03315

Please sign in to comment.