From 8bfc755ec0c73c8b2290a2b1d588e462c3c9d551 Mon Sep 17 00:00:00 2001 From: jojiang Date: Thu, 25 Aug 2022 16:45:08 +0800 Subject: [PATCH 1/2] feat(): the next site in iframe and loading bar is triggered by outerside Refs BRICK_STORE-3041 --- etc/brick-kit.api.md | 4 ++++ packages/brick-container/src/index.tsx | 18 +++++++++++++++--- .../brick-container/src/styles/default.css | 4 ++++ packages/brick-dll/manifest.snapshot.json | 1 + packages/brick-kit/src/core/Kernel.ts | 8 ++++++++ packages/brick-kit/src/index.ts | 1 + 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/etc/brick-kit.api.md b/etc/brick-kit.api.md index 68996d2b97..7657ee3162 100644 --- a/etc/brick-kit.api.md +++ b/etc/brick-kit.api.md @@ -62,6 +62,7 @@ import { RefForProxy } from '@next-core/brick-types'; import { ResolveConf } from '@next-core/brick-types'; import { RouteConf } from '@next-core/brick-types'; import type { RuntimeBootstrapData } from '@next-core/brick-types'; +import type { RuntimeMisc } from '@next-core/brick-types'; import { RuntimeStoryboard } from '@next-core/brick-types'; import { SidebarMenu } from '@next-core/brick-types'; import { SidebarSubMenu } from '@next-core/brick-types'; @@ -340,6 +341,9 @@ export const getMockInfo: (requestUrl: string, method: string) => { // @public export function getRuntime(): Runtime; +// @public (undocumented) +export function getRuntimeMisc(): RuntimeMisc; + // @public export function handleHttpError(error: Error | HttpFetchError | HttpResponseError | HttpParseError): ReturnType; diff --git a/packages/brick-container/src/index.tsx b/packages/brick-container/src/index.tsx index a05626ae3a..2e9d970724 100644 --- a/packages/brick-container/src/index.tsx +++ b/packages/brick-container/src/index.tsx @@ -10,6 +10,7 @@ import { getMockInfo, developHelper, getRuntime, + getRuntimeMisc, } from "@next-core/brick-kit"; import { http, @@ -88,6 +89,13 @@ http.interceptors.request.use(function (config: HttpRequestConfig) { }; }); +const isInSpecialFrame = (): boolean => { + return ( + getRuntimeMisc().isInIframeOfSameSite && + !getRuntimeMisc().isInIframeOfVisualBuilder + ); +}; + http.interceptors.request.use(function (config: HttpRequestConfig) { if (analyzer) { const { userInstanceId: uid, username } = getAuth(); @@ -99,15 +107,18 @@ http.interceptors.request.use(function (config: HttpRequestConfig) { username, }; } + if (!config.options?.interceptorParams?.ignoreLoadingBar) { - window.dispatchEvent(new CustomEvent("request.start")); + const curWindow = isInSpecialFrame() ? window.parent : window; + curWindow.dispatchEvent(new CustomEvent("request.start")); } return config; }); http.interceptors.response.use( function (response: HttpResponse) { - window.dispatchEvent(new CustomEvent("request.end")); + const curWindow = isInSpecialFrame() ? window.parent : window; + curWindow.dispatchEvent(new CustomEvent("request.end")); analyzer?.analyses(response); return response.config.options?.observe === "response" ? response @@ -115,7 +126,8 @@ http.interceptors.response.use( }, function (error: HttpError) { analyzer?.analyses(error); - window.dispatchEvent(new CustomEvent("request.end")); + const curWindow = isInSpecialFrame() ? window.parent : window; + curWindow.dispatchEvent(new CustomEvent("request.end")); return Promise.reject(error.error); } ); diff --git a/packages/brick-container/src/styles/default.css b/packages/brick-container/src/styles/default.css index 2cc09be510..c239732971 100644 --- a/packages/brick-container/src/styles/default.css +++ b/packages/brick-container/src/styles/default.css @@ -40,6 +40,10 @@ html[data-mode="dashboard"] #legacy-iframe-mount-point { margin-top: 0; } +.bars-hidden-in-iframe #loading-bar-mount-point { + display: none; +} + .show-legacy-iframe #main-mount-point, .bars-hidden #menu-bar-mount-point, .bars-hidden #app-bar-mount-point, diff --git a/packages/brick-dll/manifest.snapshot.json b/packages/brick-dll/manifest.snapshot.json index 4afd69b1f0..83842fda46 100644 --- a/packages/brick-dll/manifest.snapshot.json +++ b/packages/brick-dll/manifest.snapshot.json @@ -18517,6 +18517,7 @@ "getHistory", "getMockInfo", "getRuntime", + "getRuntimeMisc", "handleHttpError", "httpErrorToString", "i18nText", diff --git a/packages/brick-kit/src/core/Kernel.ts b/packages/brick-kit/src/core/Kernel.ts index 89dc7f55f6..dd2bcc032d 100644 --- a/packages/brick-kit/src/core/Kernel.ts +++ b/packages/brick-kit/src/core/Kernel.ts @@ -79,6 +79,7 @@ import { import { formDataProperties } from "./CustomForms/ExpandCustomForm"; import { formRenderer } from "./CustomForms/constants"; import { customTemplateRegistry } from "./CustomTemplates"; +import { getRuntimeMisc } from "../internal/misc"; export class Kernel { public mountPoints: MountPoints; @@ -111,6 +112,13 @@ export class Kernel { async bootstrap(mountPoints: MountPoints): Promise { listenDevtoolsEagerly(); this.mountPoints = mountPoints; + if ( + getRuntimeMisc().isInIframeOfSameSite && + !getRuntimeMisc().isInIframeOfVisualBuilder + ) { + document.body.classList.add("bars-hidden-in-iframe"); + } + await Promise.all([this.loadCheckLogin(), this.loadMicroApps()]); if (this.bootstrapData.storyboards.length === 0) { throw new Error("No storyboard were found."); diff --git a/packages/brick-kit/src/index.ts b/packages/brick-kit/src/index.ts index 04acafc616..9d6876e086 100644 --- a/packages/brick-kit/src/index.ts +++ b/packages/brick-kit/src/index.ts @@ -40,3 +40,4 @@ export * from "./featureFlags"; export * from "./core/StoryboardFunctionRegistryFactory"; export { getMockInfo } from "./core/MockRegistry"; export * from "./hooks"; +export * from "./internal/misc"; From a03e60340c77b68e2cb11d2d4963b20110d1a845 Mon Sep 17 00:00:00 2001 From: jojiang Date: Thu, 25 Aug 2022 16:49:29 +0800 Subject: [PATCH 2/2] Revert "feat(): support MISC variable" This reverts commit fa13509301b2c8a1a380c614d1fdd2cf17fa1707. --- .../manifest.snapshot.json | 1 + .../src/internal/getGeneralGlobals.spec.ts | 25 ------------------- .../src/internal/getGeneralGlobals.ts | 15 +---------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/dll/editor-bricks-helper/manifest.snapshot.json b/dll/editor-bricks-helper/manifest.snapshot.json index b446176dea..b7cf39bc64 100644 --- a/dll/editor-bricks-helper/manifest.snapshot.json +++ b/dll/editor-bricks-helper/manifest.snapshot.json @@ -196,6 +196,7 @@ "getHistory", "getMockInfo", "getRuntime", + "getRuntimeMisc", "handleHttpError", "httpErrorToString", "i18nText", diff --git a/packages/brick-kit/src/internal/getGeneralGlobals.spec.ts b/packages/brick-kit/src/internal/getGeneralGlobals.spec.ts index e52c2fb2cd..d62b491698 100644 --- a/packages/brick-kit/src/internal/getGeneralGlobals.spec.ts +++ b/packages/brick-kit/src/internal/getGeneralGlobals.spec.ts @@ -37,29 +37,4 @@ describe("getGeneralGlobals", () => { ).getCssPropertyValue("--brand-color") ).toEqual("red"); }); - - it("should get runtime misc", () => { - const attemptToVisitGlobals = new Set(["RUNTIME_MISC"]); - expect( - getGeneralGlobals(attemptToVisitGlobals, { collectCoverage: true }) - .RUNTIME_MISC - ).toEqual({ - isInIframe: false, - isInIframeOfLegacyConsole: false, - isInIframeOfNext: false, - isInIframeOfSameSite: false, - isInIframeOfVisualBuilder: false, - }); - - expect( - getGeneralGlobals(attemptToVisitGlobals, { collectCoverage: false }) - .RUNTIME_MISC - ).toEqual({ - isInIframe: false, - isInIframeOfLegacyConsole: false, - isInIframeOfNext: false, - isInIframeOfSameSite: false, - isInIframeOfVisualBuilder: false, - }); - }); }); diff --git a/packages/brick-kit/src/internal/getGeneralGlobals.ts b/packages/brick-kit/src/internal/getGeneralGlobals.ts index 5b6dfcb884..93f13dd7ce 100644 --- a/packages/brick-kit/src/internal/getGeneralGlobals.ts +++ b/packages/brick-kit/src/internal/getGeneralGlobals.ts @@ -1,6 +1,6 @@ import { getFixedT } from "i18next"; import { identity } from "lodash"; -import type { MicroApp, RuntimeMisc } from "@next-core/brick-types"; +import type { MicroApp } from "@next-core/brick-types"; import { widgetI18nFactory } from "../core/WidgetI18n"; import { i18nText } from "../i18nText"; import { getI18nNamespace } from "../i18n"; @@ -9,7 +9,6 @@ import { getBasePath } from "./getBasePath"; import { getTheme, getCssPropertyValue } from "../themeAndMode"; import { checkPermissions } from "./checkPermissions"; import { getReadOnlyProxy } from "./proxyFactories"; -import { getRuntimeMisc } from "./misc"; export interface GeneralGlobalsOptions { collectCoverage?: unknown; @@ -75,8 +74,6 @@ function getIndividualGlobal( getTheme: collectCoverage ? () => "light" : getTheme, getCssPropertyValue: collectCoverage ? () => "" : getCssPropertyValue, }; - case "RUNTIME_MISC": - return collectCoverage ? fakeRuntimeMisc() : getRuntimeMisc(); case "console": return isStoryboardFunction ? getReadOnlyProxy(console) : undefined; case "location": @@ -111,13 +108,3 @@ function fakeImageFactory(): ImagesFactory { function fakeCheckPermissions(): boolean { return true; } - -function fakeRuntimeMisc(): RuntimeMisc { - return { - isInIframe: false, - isInIframeOfSameSite: false, - isInIframeOfNext: false, - isInIframeOfVisualBuilder: false, - isInIframeOfLegacyConsole: false, - }; -}