Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 0 additions & 16 deletions packages/eui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ import React from 'react';
import type { Preview } from '@storybook/react';
import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport';

/*
* Preload all EuiIcons - Storybook does not support dynamic icon loading
* TODO: https://github.com/elastic/eui/issues/5463
*/
import { typeToPathMap } from '../src/components/icon/icon_map';
import { appendIconComponentCache } from '../src/components/icon/icon';

const iconCache: Record<string, React.FC> = {};

Object.entries(typeToPathMap).forEach(async ([iconType, iconFileName]) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const iconExport = require(`../src/components/icon/assets/${iconFileName}`);
iconCache[iconType] = iconExport.icon;
});
appendIconComponentCache(iconCache);

/**
* Ensure that any provider errors throw & warn us early
*/
Expand Down
1 change: 1 addition & 0 deletions packages/eui/changelogs/upcoming/9342.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Updated `EuiIcon` to use standard dynamic imports for icon assets, enabling native support for modern bundlers (Rollup, Parcel) and improving initial load performance
8 changes: 1 addition & 7 deletions packages/eui/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,7 @@ export class EuiIconClass extends PureComponent<
return;
}

import(
/* webpackChunkName: "icon.[request]" */
// It's important that we don't use a template string here, it
// stops webpack from building a dynamic require context.
// eslint-disable-next-line prefer-template
'./assets/' + typeToPathMap[iconType]
).then(({ icon }) => {
typeToPathMap[iconType]().then(({ icon }) => {
iconComponentCache[iconType] = icon;
enqueueStateChange(() => {
if (this.isMounted && this.props.type === iconType) {
Expand Down
Loading