From 1d9092855cf525208f3d5094a3ce85b9617ae189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=93=8D=E6=8C=87?= Date: Wed, 19 Aug 2020 15:09:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20rax=20finddom=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rax-simulator-renderer/src/renderer.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/rax-simulator-renderer/src/renderer.ts b/packages/rax-simulator-renderer/src/renderer.ts index be68ca9ca..d012dc4d9 100644 --- a/packages/rax-simulator-renderer/src/renderer.ts +++ b/packages/rax-simulator-renderer/src/renderer.ts @@ -188,8 +188,23 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer { cursor.release(); } - findDOMNodes(instance: any): Array | null { - return [raxFindDOMNodes(instance)]; + findDOMNodes(instance: any, selector?: string): Array | null { + let el = instance; + if (selector) { + el = document.querySelector(selector); + } + try { + return raxFindDOMNodes(el); + } catch (e) { + // ignore + } + if (el && el.type && el.props && el.props.componentId) { + el = document.querySelector(`${el.type}[componentid=${el.props.componentId}]`); + } else { + console.error(instance); + throw new Error('This instance may not a valid element'); + } + return raxFindDOMNodes(el); } /**