Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/components/SVGDefinitionsProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,33 @@ import React from 'react';

import LinearGradientEmptyStateBackground from './LinearGradientEmptyStateBackground';

/**
* Renders the global SVG definitions once. It is intentionally isolated from
* the rest of the provider tree so that re-renders of the app do not rebuild
* the shared <defs> and gradient elements.
*/
function SVGDefinitions(): ReactElement | null {
return (
<svg
aria-hidden
style={{height: 0, width: 0, position: 'absolute'}}
>
<defs>
<LinearGradientEmptyStateBackground />
<LinearGradientEmptyStateBackground isDarkTheme />
</defs>
</svg>
);
}

/**
* Provides global SVG definitions and helps avoid duplicated ids.
* Duplicated ids in the <defs> cause rendering issues (like missing gradients).
*/
function SVGDefinitionsProvider({children}: ChildrenProps): ReactElement | null {
return (
<>
<svg
aria-hidden
style={{height: 0, width: 0, position: 'absolute'}}
>
<defs>
<LinearGradientEmptyStateBackground />
<LinearGradientEmptyStateBackground isDarkTheme />
</defs>
</svg>
<SVGDefinitions />
{children}
</>
);
Expand Down
Loading