Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[visualizations] Reduce page load bundle to under 100kB #98302

Merged
merged 6 commits into from
May 3, 2021
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
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.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
* 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';

interface VisualizationContainerProps {
export interface VisualizationContainerProps {
'data-test-subj'?: string;
className?: string;
children: ReactNode;
Expand All @@ -22,6 +21,9 @@ 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
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 @@ -7,12 +7,12 @@
*/

import { i18n } from '@kbn/i18n';
import { SavedObjectMetaData, OnSaveProps } from 'src/plugins/saved_objects/public';
import { first } from 'rxjs/operators';
import { EmbeddableStateWithType } from 'src/plugins/embeddable/common';
import { SavedObjectAttributes } from '../../../../core/public';
import type { SavedObjectMetaData, OnSaveProps } from 'src/plugins/saved_objects/public';
import type { EmbeddableStateWithType } from 'src/plugins/embeddable/common';

import { extractSearchSourceReferences } from '../../../data/public';
import { SavedObjectReference } from '../../../../core/public';
import type { SavedObjectAttributes, SavedObjectReference } from '../../../../core/public';

import {
EmbeddableFactoryDefinition,
Expand All @@ -21,8 +21,8 @@ import {
IContainer,
AttributeService,
} from '../../../embeddable/public';
import { DisabledLabEmbeddable } from './disabled_lab_embeddable';
import {
import type { DisabledLabEmbeddable } from './disabled_lab_embeddable';
import type {
VisualizeByReferenceInput,
VisualizeByValueInput,
VisualizeEmbeddable,
Expand All @@ -31,7 +31,8 @@ import {
VisualizeSavedObjectAttributes,
} from './visualize_embeddable';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
import { SerializedVis, Vis } from '../vis';
import type { SerializedVis, Vis } from '../vis';
import { createVisAsync } from '../vis_async';
import {
getCapabilities,
getTypes,
Expand All @@ -47,10 +48,10 @@ import {
injectControlsReferences,
} from '../saved_visualizations/saved_visualization_references';
import { createVisEmbeddableFromObject } from './create_vis_embeddable_from_object';
import { StartServicesGetter } from '../../../kibana_utils/public';
import { VisualizationsStartDeps } from '../plugin';
import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants';
import { checkForDuplicateTitle } from '../../../saved_objects/public';
import type { StartServicesGetter } from '../../../kibana_utils/public';
import type { VisualizationsStartDeps } from '../plugin';

interface VisualizationAttributes extends SavedObjectAttributes {
visState: string;
Expand Down Expand Up @@ -147,8 +148,8 @@ export class VisualizeEmbeddableFactory
try {
const savedObject = await savedVisualizations.get(savedObjectId);
const visState = convertToSerializedVis(savedObject);
const vis = new Vis(savedObject.visState.type, visState);
await vis.setState(visState);
const vis = await createVisAsync(savedObject.visState.type, visState);

return createVisEmbeddableFromObject(this.deps)(
vis,
input,
Expand All @@ -167,8 +168,7 @@ export class VisualizeEmbeddableFactory
// to allow for in place creation of visualizations without having to navigate away to a new URL.
if (input.savedVis) {
const visState = input.savedVis;
const vis = new Vis(visState.type, visState);
await vis.setState(visState);
const vis = await createVisAsync(visState.type, visState);
const savedVisualizations = getSavedVisualizationsLoader();
return createVisEmbeddableFromObject(this.deps)(
vis,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/visualizations/public/index.scss

This file was deleted.

9 changes: 4 additions & 5 deletions src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@
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);
}

/** @public static code */
export { Vis } from './vis';
export { TypesService } from './vis_types/types_service';
export { VISUALIZE_EMBEDDABLE_TYPE, VIS_EVENT_TO_TRIGGER } from './embeddable';
export { VisualizationContainer } from './components';
export { getVisSchemas } from './vis_schemas';

/** @public types */
export { VisualizationsSetup, VisualizationsStart };
export { VisGroups } from './vis_types';
export { VisGroups } from './vis_types/vis_groups_enum';
export type { BaseVisType, VisTypeAlias, VisTypeDefinition, Schema, ISchemas } from './vis_types';
export { SerializedVis, SerializedVisData, VisData } from './vis';
export type { Vis, SerializedVis, SerializedVisData, VisData } from './vis';
export type VisualizeEmbeddableFactoryContract = PublicContract<VisualizeEmbeddableFactory>;
export type VisualizeEmbeddableContract = PublicContract<VisualizeEmbeddable>;
export { VisualizeInput } from './embeddable';
export { SchemaConfig } from './vis_schemas';
export { updateOldState } from './legacy/vis_update_state';
export { PersistedState } from './persisted_state';
export type { PersistedState } from './persisted_state';
export {
ISavedVis,
VisSavedObject,
Expand Down
56 changes: 28 additions & 28 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +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 {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
ApplicationStart,
SavedObjectsClientContract,
} from '../../../core/public';
import { TypesService, TypesSetup, TypesStart } from './vis_types';
import {
setUISettings,
setTypes,
Expand All @@ -42,27 +30,42 @@ import {
VisualizeEmbeddableFactory,
createVisEmbeddableFromObject,
} from './embeddable';
import { ExpressionsSetup, ExpressionsStart } from '../../expressions/public';
import { EmbeddableSetup, EmbeddableStart } from '../../embeddable/public';
import { TypesService } from './vis_types/types_service';
import { range as rangeExpressionFunction } from './expression_functions/range';
import { visDimension as visDimensionExpressionFunction } from './expression_functions/vis_dimension';
import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../plugins/data/public';
import {
Setup as InspectorSetup,
Start as InspectorStart,
} from '../../../plugins/inspector/public';
import { UsageCollectionSetup } from '../../usage_collection/public';

import { createStartServicesGetter, StartServicesGetter } from '../../kibana_utils/public';
import { createSavedVisLoader, SavedVisualizationsLoader } from './saved_visualizations';
import { SerializedVis, Vis } from './vis';
import type { SerializedVis, Vis } from './vis';
import { showNewVisModal } from './wizard';
import { UiActionsStart } from '../../ui_actions/public';

import {
convertFromSerializedVis,
convertToSerializedVis,
} from './saved_visualizations/_saved_vis';

import { createSavedSearchesLoader } from '../../discover/public';
import { SavedObjectsStart } from '../../saved_objects/public';

import type {
PluginInitializerContext,
CoreSetup,
CoreStart,
Plugin,
ApplicationStart,
SavedObjectsClientContract,
} from '../../../core/public';
import type { UsageCollectionSetup } from '../../usage_collection/public';
import type { UiActionsStart } from '../../ui_actions/public';
import type { SavedObjectsStart } from '../../saved_objects/public';
import type { TypesSetup, TypesStart } from './vis_types';
import type {
Setup as InspectorSetup,
Start as InspectorStart,
} from '../../../plugins/inspector/public';
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_async';

/**
* Interface for this plugin's returned setup/start contracts.
Expand Down Expand Up @@ -180,11 +183,8 @@ export class VisualizationsPlugin
* @param {IIndexPattern} indexPattern - index pattern to use
* @param {VisState} visState - visualization configuration
*/
createVis: async (visType: string, visState: SerializedVis) => {
const vis = new Vis(visType);
await vis.setState(visState);
return vis;
},
createVis: async (visType: string, visState: SerializedVis) =>
await createVisAsync(visType, visState),
convertToSerializedVis,
convertFromSerializedVis,
savedVisualizationsLoader,
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 @@ -14,7 +14,7 @@ import {
SavedObjectsFindOptions,
} from '../../../../core/public';
import { SavedObjectLoader } from '../../../../plugins/saved_objects/public';
import { VisTypeAlias } from '../vis_types';
import type { VisTypeAlias } from '../vis_types';
import { VisualizationsAppExtension } from '../vis_types/vis_type_alias_registry';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* 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';
import { TypesStart } from '../vis_types';
import type { TypesStart } from '../vis_types';

export interface SavedVisServicesWithVisualizations extends SavedVisServices {
visualizationTypes: TypesStart;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/visualizations/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import {
import type {
ApplicationStart,
Capabilities,
ChromeStart,
Expand All @@ -16,7 +16,7 @@ import {
SavedObjectsStart,
DocLinksStart,
} from '../../../core/public';
import { TypesStart } from './vis_types';
import type { TypesStart } from './vis_types';
import { createGetterSetter } from '../../../plugins/kibana_utils/public';
import { DataPublicPluginStart, TimefilterContract } from '../../../plugins/data/public';
import { UsageCollectionSetup } from '../../../plugins/usage_collection/public';
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/visualizations/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
} from '../../../plugins/data/public';
import { ExpressionAstExpression } from '../../expressions/public';

import { SerializedVis, Vis } from './vis';
import { PersistedState } from './persisted_state';
import { VisParams } from '../common';
import type { SerializedVis, Vis } from './vis';
import type { PersistedState } from './persisted_state';
import type { VisParams } from '../common';

export { Vis, SerializedVis, VisParams };
export type { Vis, SerializedVis, VisParams };
export interface SavedVisState {
title: string;
type: string;
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,6 @@ export class Vis<TVisParams = VisParams> {
return newConfigs;
}
}

// eslint-disable-next-line import/no-default-export
export default Vis;
Loading