-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime): 修复 Vue3.2+ 版本静态节点渲染报错的问题,fix #10077
- Loading branch information
Showing
13 changed files
with
136 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
import { isFunction, warn } from '@tarojs/shared' | ||
import { inject, injectable, optional } from 'inversify' | ||
import SERVICE_IDENTIFIER from '../constants/identifiers' | ||
import { injectable } from 'inversify' | ||
import { getBoundingClientRectImpl, getTemplateContent } from './element' | ||
|
||
import type { Ctx } from '../interface' | ||
import type { getBoundingClientRectImpl } from './element' | ||
|
||
declare const ENABLE_SIZE_APIS: boolean | ||
declare const ENABLE_TEMPLATE_CONTENT: boolean | ||
|
||
@injectable() | ||
export class TaroElementImpl { | ||
public rectImpl: typeof getBoundingClientRectImpl | ||
|
||
constructor (// eslint-disable-next-line @typescript-eslint/indent | ||
@inject(SERVICE_IDENTIFIER.getBoundingClientRectImpl) @optional() rectImpl: typeof getBoundingClientRectImpl | ||
) { | ||
this.rectImpl = rectImpl | ||
} | ||
|
||
bind (ctx: Ctx) { | ||
this.bindRect(ctx) | ||
} | ||
|
||
bindRect (ctx: Ctx) { | ||
const impl = this.rectImpl | ||
ctx.getBoundingClientRect = async function (...args: any[]) { | ||
if (isFunction(impl)) { | ||
return await impl.apply(ctx, args) | ||
if (ENABLE_SIZE_APIS) { | ||
ctx.getBoundingClientRect = async function (...args: any[]) { | ||
return await getBoundingClientRectImpl.apply(ctx, args) | ||
} | ||
|
||
process.env.NODE_ENV !== 'production' && warn(true, '请实现 element.getBoundingClientRect') | ||
return Promise.resolve(null) | ||
} | ||
if (ENABLE_TEMPLATE_CONTENT) { | ||
bindContent(ctx) | ||
} | ||
} | ||
} | ||
|
||
function bindContent (ctx: Ctx) { | ||
Object.defineProperty(ctx, 'content', { | ||
configurable: true, | ||
enumerable: true, | ||
get () { | ||
return getTemplateContent(ctx) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,57 @@ | ||
import { isFunction, warn } from '@tarojs/shared' | ||
import { inject, injectable, optional } from 'inversify' | ||
import { inject, injectable } from 'inversify' | ||
import SERVICE_IDENTIFIER from '../constants/identifiers' | ||
import { ElementNames, InstanceNamedFactory } from '../interface' | ||
import { setInnerHTML } from '../dom-external/inner-html/html' | ||
import { cloneNode, insertAdjacentHTMLImpl } from './node' | ||
|
||
import type { Ctx, GetDoc } from '../interface' | ||
import type { setInnerHTML } from '../dom-external/inner-html/html' | ||
import type { TaroDocument } from '../dom/document' | ||
import type { insertAdjacentHTMLImpl, IPosition } from './node' | ||
import type { IPosition } from './node' | ||
|
||
type SetInnerHTML = typeof setInnerHTML | ||
type InsertAdjacentHTMLImpl = typeof insertAdjacentHTMLImpl | ||
declare const ENABLE_INNER_HTML: boolean | ||
declare const ENABLE_ADJACENT_HTML: boolean | ||
declare const ENABLE_CLONE_NODE: boolean | ||
|
||
@injectable() | ||
export class TaroNodeImpl { | ||
ctx: Ctx | ||
public getDoc: GetDoc | ||
public innerHTMLImpl: SetInnerHTML | ||
public adjacentImpl: InsertAdjacentHTMLImpl | ||
|
||
constructor (// eslint-disable-next-line @typescript-eslint/indent | ||
@inject(SERVICE_IDENTIFIER.TaroElementFactory) getElement: InstanceNamedFactory, | ||
@inject(SERVICE_IDENTIFIER.InnerHTMLImpl) @optional() innerHTMLImpl: SetInnerHTML, | ||
@inject(SERVICE_IDENTIFIER.insertAdjacentHTMLImpl) @optional() adjacentImpl: InsertAdjacentHTMLImpl | ||
@inject(SERVICE_IDENTIFIER.TaroElementFactory) getElement: InstanceNamedFactory | ||
) { | ||
this.getDoc = () => getElement<TaroDocument>(ElementNames.Document)() | ||
this.innerHTMLImpl = innerHTMLImpl | ||
this.adjacentImpl = adjacentImpl | ||
} | ||
|
||
public bind (ctx: Ctx) { | ||
this.ctx = ctx | ||
this.bindInnerHTML() | ||
this.bindAdjacentHTML() | ||
} | ||
const getDoc = this.getDoc | ||
|
||
private bindInnerHTML () { | ||
const { ctx, innerHTMLImpl: impl, getDoc } = this | ||
Object.defineProperty(ctx, 'innerHTML', { | ||
configurable: true, | ||
enumerable: true, | ||
set (html: string) { | ||
if (isFunction(impl)) { | ||
impl.call(ctx, ctx, html, getDoc) | ||
} else { | ||
process.env.NODE_ENV !== 'production' && warn(true, '请实现 node.innerHTML') | ||
} | ||
}, | ||
get (): string { | ||
return '' | ||
if (ENABLE_INNER_HTML) { | ||
bindInnerHTML(ctx, getDoc) | ||
if (ENABLE_ADJACENT_HTML) { | ||
bindAdjacentHTML(ctx, getDoc) | ||
} | ||
}) | ||
} | ||
if (ENABLE_CLONE_NODE) { | ||
ctx.cloneNode = cloneNode.bind(ctx, ctx, getDoc) | ||
} | ||
} | ||
} | ||
|
||
private bindAdjacentHTML () { | ||
const { ctx, adjacentImpl: impl, getDoc } = this | ||
ctx.insertAdjacentHTML = function (position: IPosition, html: string) { | ||
if (isFunction(impl)) { | ||
impl.call(ctx, position, html, getDoc) | ||
} else { | ||
process.env.NODE_ENV !== 'production' && warn(true, '请实现 node.insertAdjacentHTML') | ||
} | ||
function bindInnerHTML (ctx, getDoc) { | ||
Object.defineProperty(ctx, 'innerHTML', { | ||
configurable: true, | ||
enumerable: true, | ||
set (html: string) { | ||
setInnerHTML.call(ctx, ctx, html, getDoc) | ||
}, | ||
get (): string { | ||
return '' | ||
} | ||
}) | ||
} | ||
|
||
function bindAdjacentHTML (ctx, getDoc) { | ||
ctx.insertAdjacentHTML = function (position: IPosition, html: string) { | ||
insertAdjacentHTMLImpl.call(ctx, position, html, getDoc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { TaroElement } from './element' | ||
|
||
// for Vue3 | ||
export class SVGElement extends TaroElement {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters