From b58489d89b8367ae1edcf2f2214e09610467e3a5 Mon Sep 17 00:00:00 2001 From: zhangjiliang Date: Mon, 19 May 2025 17:06:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=E4=BF=9D=E6=8C=81link=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=89=A7=E8=A1=8C=E9=A1=BA=E5=BA=8F=E5=92=8C?= =?UTF-8?q?=E5=9C=A8dom=E6=96=87=E6=A1=A3=E4=B8=AD=E7=9A=84=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/source/links.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/source/links.ts b/src/source/links.ts index 057a00dbc..0b700e7e3 100644 --- a/src/source/links.ts +++ b/src/source/links.ts @@ -28,7 +28,7 @@ import globalEnv from '../libs/global_env' * @param appName app.name * @param linkInfo linkInfo of current address */ -function getExistParseCode ( +function getExistParseCode( appName: string, prefix: string, linkInfo: LinkSourceInfo, @@ -45,7 +45,7 @@ function getExistParseCode ( } // transfer the attributes on the link to convertStyle -function setConvertStyleAttr (convertStyle: HTMLStyleElement, attrs: AttrsType): void { +function setConvertStyleAttr(convertStyle: HTMLStyleElement, attrs: AttrsType): void { attrs.forEach((value, key) => { if (key === 'rel') return if (key === 'href') key = 'data-origin-href' @@ -61,7 +61,7 @@ function setConvertStyleAttr (convertStyle: HTMLStyleElement, attrs: AttrsType): * @param microAppHead micro-app-head element * @param isDynamic dynamic insert */ -export function extractLinkFromHtml ( +export function extractLinkFromHtml( link: HTMLLinkElement, parent: Node | null, app: AppInterface, @@ -121,7 +121,7 @@ export function extractLinkFromHtml ( * @param app app * @param microAppHead micro-app-head */ -export function fetchLinksFromHtml ( +export function fetchLinksFromHtml( wrapElement: HTMLElement, app: AppInterface, microAppHead: Element, @@ -134,15 +134,18 @@ export function fetchLinksFromHtml ( }) const fiberLinkTasks: fiberTasks = fiberStyleResult ? [] : null + + //Keep the execution order of link code consistent with their order in the DOM document. + const eachCallBacks: Array = [] promiseStream(fetchLinkPromise, (res: { data: string, index: number }) => { - injectFiberTask(fiberLinkTasks, () => fetchLinkSuccess( + eachCallBacks[res.index] = () => injectFiberTask(fiberLinkTasks, () => fetchLinkSuccess( styleList[res.index], res.data, microAppHead, app, )) - }, (err: {error: Error, index: number}) => { + }, (err: { error: Error, index: number }) => { logError(err, app.name) }, () => { /** @@ -150,6 +153,8 @@ export function fetchLinksFromHtml ( * 2. Download link source while processing style * 3. Process style first, and then process link */ + eachCallBacks.forEach((callback) => callback()) + if (fiberStyleResult) { fiberStyleResult.then(() => { fiberLinkTasks!.push(() => Promise.resolve(app.onLoad({ html: wrapElement }))) @@ -174,7 +179,7 @@ export function fetchLinksFromHtml ( * @param microAppHead micro-app-head * @param app app instance */ -export function fetchLinkSuccess ( +export function fetchLinkSuccess( address: string, code: string, microAppHead: Element, @@ -229,7 +234,7 @@ export function fetchLinkSuccess ( * @param linkInfo linkInfo in sourceCenter * @param attrs attrs of link */ -export function handleConvertStyle ( +export function handleConvertStyle( app: AppInterface, address: string, convertStyle: HTMLStyleElement, @@ -265,7 +270,7 @@ export function handleConvertStyle ( * @param linkInfo linkInfo * @param originLink origin link element */ -export function formatDynamicLink ( +export function formatDynamicLink( address: string, app: AppInterface, linkInfo: LinkSourceInfo, From 9ba9ce29238e3f05e67593dbe196c09ab9669fed Mon Sep 17 00:00:00 2001 From: zhangjiliang Date: Tue, 13 Jan 2026 10:34:09 +0800 Subject: [PATCH 2/2] refactor:remove the formatter of vscode --- src/source/links.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/source/links.ts b/src/source/links.ts index 0b700e7e3..807188de1 100644 --- a/src/source/links.ts +++ b/src/source/links.ts @@ -28,7 +28,7 @@ import globalEnv from '../libs/global_env' * @param appName app.name * @param linkInfo linkInfo of current address */ -function getExistParseCode( +function getExistParseCode ( appName: string, prefix: string, linkInfo: LinkSourceInfo, @@ -45,7 +45,7 @@ function getExistParseCode( } // transfer the attributes on the link to convertStyle -function setConvertStyleAttr(convertStyle: HTMLStyleElement, attrs: AttrsType): void { +function setConvertStyleAttr (convertStyle: HTMLStyleElement, attrs: AttrsType): void { attrs.forEach((value, key) => { if (key === 'rel') return if (key === 'href') key = 'data-origin-href' @@ -61,7 +61,7 @@ function setConvertStyleAttr(convertStyle: HTMLStyleElement, attrs: AttrsType): * @param microAppHead micro-app-head element * @param isDynamic dynamic insert */ -export function extractLinkFromHtml( +export function extractLinkFromHtml ( link: HTMLLinkElement, parent: Node | null, app: AppInterface, @@ -121,7 +121,7 @@ export function extractLinkFromHtml( * @param app app * @param microAppHead micro-app-head */ -export function fetchLinksFromHtml( +export function fetchLinksFromHtml ( wrapElement: HTMLElement, app: AppInterface, microAppHead: Element, @@ -134,7 +134,7 @@ export function fetchLinksFromHtml( }) const fiberLinkTasks: fiberTasks = fiberStyleResult ? [] : null - + //Keep the execution order of link code consistent with their order in the DOM document. const eachCallBacks: Array = [] @@ -145,7 +145,7 @@ export function fetchLinksFromHtml( microAppHead, app, )) - }, (err: { error: Error, index: number }) => { + }, (err: {error: Error, index: number}) => { logError(err, app.name) }, () => { /** @@ -154,7 +154,6 @@ export function fetchLinksFromHtml( * 3. Process style first, and then process link */ eachCallBacks.forEach((callback) => callback()) - if (fiberStyleResult) { fiberStyleResult.then(() => { fiberLinkTasks!.push(() => Promise.resolve(app.onLoad({ html: wrapElement }))) @@ -179,7 +178,7 @@ export function fetchLinksFromHtml( * @param microAppHead micro-app-head * @param app app instance */ -export function fetchLinkSuccess( +export function fetchLinkSuccess ( address: string, code: string, microAppHead: Element, @@ -234,7 +233,7 @@ export function fetchLinkSuccess( * @param linkInfo linkInfo in sourceCenter * @param attrs attrs of link */ -export function handleConvertStyle( +export function handleConvertStyle ( app: AppInterface, address: string, convertStyle: HTMLStyleElement, @@ -270,7 +269,7 @@ export function handleConvertStyle( * @param linkInfo linkInfo * @param originLink origin link element */ -export function formatDynamicLink( +export function formatDynamicLink ( address: string, app: AppInterface, linkInfo: LinkSourceInfo,