Skip to content

Commit

Permalink
move scss to async chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Apr 27, 2021
1 parent 87e040a commit f222616
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pageLoadAssetSize:
visTypeVega: 153573
visTypeVislib: 242838
visTypeXy: 113478
visualizations: 295025
visualizations: 90000
visualize: 57431
watcher: 43598
runtimeFields: 41752
Expand Down
1 change: 0 additions & 1 deletion src/plugins/visualizations/public/components/_index.scss

This file was deleted.

4 changes: 1 addition & 3 deletions src/plugins/visualizations/public/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
* Side Public License, v 1.
*/

import { lazy } from 'react';

export const VisualizationContainer = lazy(() => import('./visualization_container'));
export { VisualizationContainer } from './visualization_container';
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
* Side Public License, v 1.
*/

import React, { ReactNode, Suspense } from 'react';
import React, { ReactNode, Suspense, lazy } from 'react';
import { EuiLoadingChart } from '@elastic/eui';
import classNames from 'classnames';
import { VisualizationNoResults } from './visualization_noresults';
import { VisualizationError } from './visualization_error';

import { IInterpreterRenderHandlers } from '../../../expressions/common';

export interface VisualizationContainerProps {
Expand All @@ -22,6 +21,9 @@ export interface VisualizationContainerProps {
error?: string;
}

const VisualizationNoResults = lazy(() => import('./visualization_noresults'));
const VisualizationError = lazy(() => import('./visualization_error'));

export const VisualizationContainer = ({
'data-test-subj': dataTestSubj = '',
className,
Expand Down Expand Up @@ -52,6 +54,3 @@ export const VisualizationContainer = ({
</div>
);
};

// eslint-disable-next-line import/no-default-export
export default VisualizationContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ export class VisualizationError extends React.Component<VisualizationNoResultsPr
}
}
}

// eslint-disable-next-line import/no-default-export
export default VisualizationError;
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ export class VisualizationNoResults extends React.Component<VisualizationNoResul
}
}
}

// eslint-disable-next-line import/no-default-export
export default VisualizationNoResults;
1 change: 0 additions & 1 deletion src/plugins/visualizations/public/embeddable/_index.scss

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Vis } from '../types';
import {
import type {
VisualizeInput,
VisualizeEmbeddable,
VisualizeByValueInput,
Expand All @@ -31,6 +31,7 @@ import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants';
import { SavedVisualizationsLoader } from '../saved_visualizations';
import { IndexPattern } from '../../../data/public';
import { createVisualizeEmbeddableAsync } from './visualize_embeddable_async';

export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDeps) => async (
vis: Vis,
Expand Down Expand Up @@ -72,7 +73,7 @@ export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDe
dashboardSave: Boolean(getCapabilities().dashboard?.showWriteControls),
};

return new VisualizeEmbeddable(
return createVisualizeEmbeddableAsync(
getTimeFilter(),
{
vis,
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/visualizations/public/embeddable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*/

export { DisabledLabEmbeddable } from './disabled_lab_embeddable';
export { VisualizeEmbeddable, VisualizeInput } from './visualize_embeddable';
export { VisualizeEmbeddableFactory } from './visualize_embeddable_factory';
export { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
export { VIS_EVENT_TO_TRIGGER } from './events';
export { createVisEmbeddableFromObject } from './create_vis_embeddable_from_object';

export type { VisualizeEmbeddable, VisualizeInput } from './visualize_embeddable';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { VisualizeEmbeddable as VisualizeEmbeddableType } from './visualize_embeddable';

export const createVisualizeEmbeddableAsync = async (
...args: ConstructorParameters<typeof VisualizeEmbeddableType>
) => {
// Build optimization. Move app styles from main bundle
// @ts-expect-error TS error, cannot find type declaration for scss
await import('./embeddables.scss');

const { VisualizeEmbeddable } = await import('./visualize_embeddable');

return new VisualizeEmbeddable(...args);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
AttributeService,
} from '../../../embeddable/public';
import type { DisabledLabEmbeddable } from './disabled_lab_embeddable';
import {
import type {
VisualizeByReferenceInput,
VisualizeByValueInput,
VisualizeEmbeddable,
Expand All @@ -32,7 +32,7 @@ import {
} from './visualize_embeddable';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
import type { SerializedVis, Vis } from '../vis';
import { createVisAsync } from '../vis_lazy';
import { createVisAsync } from '../vis_async';
import {
getCapabilities,
getTypes,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/visualizations/public/index.scss

This file was deleted.

2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { PublicContract } from '@kbn/utility-types';
import { PluginInitializerContext } from 'src/core/public';
import { VisualizationsPlugin, VisualizationsSetup, VisualizationsStart } from './plugin';
import { VisualizeEmbeddableFactory, VisualizeEmbeddable } from './embeddable';
import type { VisualizeEmbeddableFactory, VisualizeEmbeddable } from './embeddable';

export function plugin(initializerContext: PluginInitializerContext) {
return new VisualizationsPlugin(initializerContext);
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import './index.scss';

import {
setUISettings,
setTypes,
Expand Down Expand Up @@ -68,7 +65,7 @@ import type {
import type { DataPublicPluginSetup, DataPublicPluginStart } from '../../../plugins/data/public';
import type { ExpressionsSetup, ExpressionsStart } from '../../expressions/public';
import type { EmbeddableSetup, EmbeddableStart } from '../../embeddable/public';
import { createVisAsync } from './vis_lazy';
import { createVisAsync } from './vis_async';

/**
* Interface for this plugin's returned setup/start contracts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*
* NOTE: It's a type of SavedObject, but specific to visualizations.
*/
import { SavedObjectsStart, SavedObject } from '../../../../plugins/saved_objects/public';
import type { SavedObjectsStart, SavedObject } from '../../../../plugins/saved_objects/public';
// @ts-ignore
import { updateOldState } from '../legacy/vis_update_state';
import { extractReferences, injectReferences } from './saved_visualization_references';
import { IIndexPattern, IndexPatternsContract } from '../../../../plugins/data/public';
import { ISavedVis, SerializedVis } from '../types';
import { createSavedSearchesLoader } from '../../../discover/public';
import { SavedObjectsClientContract } from '../../../../core/public';
import type { SavedObjectsClientContract } from '../../../../core/public';
import type { IIndexPattern, IndexPatternsContract } from '../../../../plugins/data/public';
import type { ISavedVis, SerializedVis } from '../types';

export interface SavedVisServices {
savedObjectsClient: SavedObjectsClientContract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { SavedObjectReference, SavedObjectsFindOptionsReference } from 'kibana/public';
import type { SavedObjectReference, SavedObjectsFindOptionsReference } from 'kibana/public';
import { SavedObjectLoader } from '../../../../plugins/saved_objects/public';
import { findListItems } from './find_list_items';
import { createSavedVisClass, SavedVisServices } from './_saved_vis';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ export const createVisAsync = async <TVisParams = VisParams>(
visType: string,
visState: SerializedVis<TVisParams> = {} as any
) => {
// Build optimization. Move app styles from main bundle
// @ts-expect-error TS error, cannot find type declaration for scss
await import('./vis.scss');

const { Vis } = await import('./vis');
const vis = new Vis(visType, visState);

await vis.setState(visState);
return vis;
};

0 comments on commit f222616

Please sign in to comment.