diff --git a/packages/uni-app-plus/dist/uni-app-view.umd.js b/packages/uni-app-plus/dist/uni-app-view.umd.js index 0de6c8f3265d10f98b3c6e6826150513c9a9fbea..c86a5e92fbb814da89ec9e97e8df2a8880305f85 100644 --- a/packages/uni-app-plus/dist/uni-app-view.umd.js +++ b/packages/uni-app-plus/dist/uni-app-view.umd.js @@ -12201,7 +12201,10 @@ setText(text2) { this.$.textContent = text2; } - insert(parentNodeId, refNodeId) { + insert(parentNodeId, refNodeId, nodeJson) { + if (nodeJson) { + this.init(nodeJson, false); + } var node = this.$; var parentNode = $(parentNodeId); if (refNodeId === -1) { @@ -12450,6 +12453,7 @@ this.insert(parentNodeId, refNodeId); } init(nodeJson) { + var isCreate = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true; if (hasOwn$1(nodeJson, "a")) { this.setAttrs(nodeJson.a); } @@ -12463,12 +12467,14 @@ this.addWxsEvents(nodeJson.w); } super.init(nodeJson); - watch(this.$props, () => { - queuePostActionJob(this._update, JOB_PRIORITY_UPDATE); - }, { - flush: "sync" - }); - this.update(true); + if (isCreate) { + watch(this.$props, () => { + queuePostActionJob(this._update, JOB_PRIORITY_UPDATE); + }, { + flush: "sync" + }); + this.update(true); + } } setAttrs(attrs2) { this.setWxsProps(attrs2); @@ -22901,7 +22907,7 @@ var parentNodeId = action[3]; return createElement(action[1], getDict(action[2]), parentNodeId === -1 ? 0 : parentNodeId, action[4], decodeNodeJson(getDict, action[5])); case ACTION_TYPE_INSERT: - return $(action[1]).insert(action[2], action[3]); + return $(action[1]).insert(action[2], action[3], decodeNodeJson(getDict, action[4])); case ACTION_TYPE_REMOVE: return $(action[1]).remove(); case ACTION_TYPE_SET_ATTRIBUTE: diff --git a/packages/uni-app-plus/dist/uni.runtime.esm.js b/packages/uni-app-plus/dist/uni.runtime.esm.js index e24d8d2f9714b98d372f2bd6a8b465c2bf6a07df..775231e9868777551acb9102807c026c5ac87fbf 100644 --- a/packages/uni-app-plus/dist/uni.runtime.esm.js +++ b/packages/uni-app-plus/dist/uni.runtime.esm.js @@ -17947,6 +17947,9 @@ class UniPageNode extends UniNode { } else { // 部分手机上,create 和 insert 可能不在同一批次,被分批发送 + if (extras) { + action[4] = extras; + } this.updateActions.push(action); // if ((process.env.NODE_ENV !== 'production')) { // console.error(formatLog(`Insert`, action, 'not found createAction')) diff --git a/packages/uni-app-plus/src/service/framework/dom/Page.ts b/packages/uni-app-plus/src/service/framework/dom/Page.ts index c58c7ae978fe21ef4405f3d5f0e60664f770524f..3f3a7528f4a0833315046d0b0f8ac9dcaaf8b3a0 100644 --- a/packages/uni-app-plus/src/service/framework/dom/Page.ts +++ b/packages/uni-app-plus/src/service/framework/dom/Page.ts @@ -213,6 +213,9 @@ export default class UniPageNode extends UniNode implements IUniPageNode { } } else { // 部分手机上,create 和 insert 可能不在同一批次,被分批发送 + if (extras) { + action[4] = extras as UniNodeJSON + } this.updateActions.push(action) // if (__DEV__) { // console.error(formatLog(`Insert`, action, 'not found createAction')) diff --git a/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts b/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts index a3cc99718a142aeb621a0dc4a2094a71dd7ad3d2..e6829ec9166aa97233d364d59768b4f7f8c0910e 100644 --- a/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts +++ b/packages/uni-app-plus/src/view/framework/dom/components/UniComponent.ts @@ -71,7 +71,7 @@ export class UniComponent extends UniNode { // 延迟到insert之后,再flush,确保mounted等生命周期触发正常 flushPostFlushCbs() } - init(nodeJson: Partial) { + init(nodeJson: Partial, isCreate: boolean = true) { const { a, e, w } = nodeJson if (a) { // 初始化时,先提取 wxsProps,再 setAttr diff --git a/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts b/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts index 67ba3cf8022ba3b567cbfff43c2fbbc89ee039d9..fb28dfb098659c53000c58df0df30067a490e9aa 100644 --- a/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts +++ b/packages/uni-app-plus/src/view/framework/dom/elements/UniElement.ts @@ -45,7 +45,7 @@ export class UniElement extends UniNode { this.init(nodeJson) this.insert(parentNodeId, refNodeId) } - init(nodeJson: Partial) { + init(nodeJson: Partial, isCreate: boolean = true) { if (hasOwn(nodeJson, 'a')) { this.setAttrs(nodeJson.a!) } @@ -59,14 +59,17 @@ export class UniElement extends UniNode { this.addWxsEvents(nodeJson.w!) } super.init(nodeJson) - watch( - this.$props, - () => { - queuePostActionJob(this._update!, JOB_PRIORITY_UPDATE) - }, - { flush: 'sync' } - ) - this.update(true) + // insert 的时候可能也会调用该 init + if (isCreate) { + watch( + this.$props, + () => { + queuePostActionJob(this._update!, JOB_PRIORITY_UPDATE) + }, + { flush: 'sync' } + ) + this.update(true) + } } setAttrs(attrs: Record) { // 初始化时,先提取 wxsProps,再 setAttr diff --git a/packages/uni-app-plus/src/view/framework/dom/elements/UniNode.ts b/packages/uni-app-plus/src/view/framework/dom/elements/UniNode.ts index 2171ed6b41b3d174b555bf58b02611701430f1ed..a7ad29ebb665aaa8be3cdafad3a5d8f4ed4f98ea 100644 --- a/packages/uni-app-plus/src/view/framework/dom/elements/UniNode.ts +++ b/packages/uni-app-plus/src/view/framework/dom/elements/UniNode.ts @@ -36,7 +36,7 @@ export class UniNode { parent.appendUniChild(this) } } - init(nodeJson: Partial) { + init(nodeJson: Partial, isCreate: boolean = true) { if (hasOwn(nodeJson, 't')) { this.$.textContent = nodeJson.t as string } @@ -44,7 +44,15 @@ export class UniNode { setText(text: string) { this.$.textContent = text } - insert(parentNodeId: number, refNodeId: number) { + insert( + parentNodeId: number, + refNodeId: number, + nodeJson?: Partial + ) { + // 部分性能低的手机,create 和 insert 是分开的,而 nodeJson 可能随着 insert + if (nodeJson) { + this.init(nodeJson, false) + } const node = this.$ const parentNode = $(parentNodeId) if (refNodeId === -1) { diff --git a/packages/uni-app-plus/src/view/framework/dom/index.ts b/packages/uni-app-plus/src/view/framework/dom/index.ts index 98039d7c504faef9eccbecbcb00ba2e15695b2c0..5ba2df574d3efbd6f07087b9a07bfdb048d6eb59 100644 --- a/packages/uni-app-plus/src/view/framework/dom/index.ts +++ b/packages/uni-app-plus/src/view/framework/dom/index.ts @@ -68,7 +68,11 @@ function onPageUpdateSync(actions: (PageAction | DictAction)[]) { decodeNodeJson(getDict, action[5] as UniNodeJSONMinify) ) case ACTION_TYPE_INSERT: - return $(action[1]).insert(action[2], action[3]) + return $(action[1]).insert( + action[2], + action[3], + decodeNodeJson(getDict, action[4] as UniNodeJSONMinify) + ) case ACTION_TYPE_REMOVE: return $(action[1]).remove() case ACTION_TYPE_SET_ATTRIBUTE: diff --git a/packages/uni-shared/dist/uni-shared.d.ts b/packages/uni-shared/dist/uni-shared.d.ts index 0a8a3c985928b75a584ba8b8028b3ca9d53f9cf0..d39ec0ba48bc0f4f24c7b0787e3bf28d3d6d0b41 100644 --- a/packages/uni-shared/dist/uni-shared.d.ts +++ b/packages/uni-shared/dist/uni-shared.d.ts @@ -240,8 +240,15 @@ export declare const initCustomDatasetOnce: () => void; * nodeId * parentNodeId * refNodeId + * nodeJson */ -export declare type InsertAction = [typeof ACTION_TYPE_INSERT, number, number, number]; +export declare type InsertAction = [ +typeof ACTION_TYPE_INSERT, +number, +number, +number, +Partial? +]; export declare const invokeArrayFns: (fns: Function[], arg?: any) => any; diff --git a/packages/uni-shared/src/vdom/Action.ts b/packages/uni-shared/src/vdom/Action.ts index 627dc0d713c991aeb2e0781200ca8ec7440523ad..cff50823ac13e2b1f1729dd3a7e0d0b4618d8099 100644 --- a/packages/uni-shared/src/vdom/Action.ts +++ b/packages/uni-shared/src/vdom/Action.ts @@ -58,8 +58,15 @@ export type CreateAction = [ * nodeId * parentNodeId * refNodeId + * nodeJson */ -export type InsertAction = [typeof ACTION_TYPE_INSERT, number, number, number] +export type InsertAction = [ + typeof ACTION_TYPE_INSERT, + number, + number, + number, + Partial? +] /** * nodeId