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
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = [
},
{
path: "packages/brick-kit/dist/index.esm.js",
limit: "111 KB",
limit: "115 KB",
},
{
path: "packages/brick-types/dist/index.esm.js",
Expand Down
13 changes: 13 additions & 0 deletions etc/brick-types.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,19 @@ export interface NavbarConf {
menuBar: string;
}

// @public (undocumented)
export interface NavTip {
// (undocumented)
closeable?: boolean;
// (undocumented)
info?: {
url: string;
label: string;
};
// (undocumented)
text: string;
}

// Warning: (ae-internal-missing-underscore) The name "OmitListener" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
Expand Down
32 changes: 32 additions & 0 deletions packages/brick-kit/src/core/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
PluginLocation,
PluginRuntimeContext,
RuntimeMisc,
NavTip,
} from "@next-core/brick-types";
import {
restoreDynamicTemplates,
Expand Down Expand Up @@ -234,6 +235,7 @@ export class Router {
const history = getHistory();
history.unblock();

const renderStartTime = performance.now();
// Create the page tracker before page load.
// And the API Analyzer maybe disabled.
const pageTracker = apiAnalyzer.getInstance()?.pageTracker();
Expand Down Expand Up @@ -559,6 +561,36 @@ export class Router {
pageTitle: document.title,
});

const renderTime = performance.now() - renderStartTime;
const { loadTime = 0, loadInfoPage } =
this.kernel.bootstrapData.settings?.misc ?? {};
if (currentApp.isBuildPush && loadTime > 0 && renderTime > loadTime) {
const getSecond = (time: number): number =>
Math.floor(time * 100) / 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里计算的时候进行了 floor,但是前面判断的时候却没有 floor,那么可能出现这种情况:renderTime = 2.509s,提示用户超时,但是,界面上会显示为「您的页面存在性能问题, 当前页面渲染时间为: 2.5s,规定阈值为: 2.5s」,这有些奇怪。

window.dispatchEvent(
new CustomEvent<NavTip[]>("app.bar.tips", {
detail: [
{
text: `您的页面存在性能问题, 当前页面渲染时间为: ${getSecond(
renderTime / 1000
)} 秒, 规定阈值为: ${getSecond(
(loadTime as number) / 1000
)} 秒; 您已超过, 请您针对该页面进行性能优化!`,
closeable: false,
...(loadInfoPage
? {
info: {
label: "查看详情",
url: loadInfoPage as string,
},
}
: {}),
},
],
})
);
}

// analytics page_view event
userAnalytics.event("page_view", {
micro_app_id: this.kernel.currentApp.id,
Expand Down
9 changes: 9 additions & 0 deletions packages/brick-types/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ export interface UserInfo {
user_memo: string;
}

export interface NavTip {
text: string;
closeable?: boolean;
info?: {
url: string;
label: string;
};
}

/** @internal */
export interface MagicBrickConfig {
selector: string;
Expand Down