From 4f48f1fe9ec0256356bc75ffe91c48102f3ec706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E6=9E=9C?= Date: Tue, 14 Jul 2020 16:28:10 +0800 Subject: [PATCH] release: rax@1.1.4 (#1953) * fix: should trigger afterRender twice when render to the same target twice (#1952) * fix: createPortal mount not trigger afterRender * fix: createPortal mount() not trigger afterRender * chore: add test case --- packages/rax/package.json | 2 +- packages/rax/src/__tests__/render.js | 20 ++++++++++++++++---- packages/rax/src/vdom/instance.js | 6 +++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/rax/package.json b/packages/rax/package.json index bea100fceb..9940d54e7e 100644 --- a/packages/rax/package.json +++ b/packages/rax/package.json @@ -1,6 +1,6 @@ { "name": "rax", - "version": "1.1.3", + "version": "1.1.4", "description": "A universal React-compatible render engine.", "license": "BSD-3-Clause", "main": "index.js", diff --git a/packages/rax/src/__tests__/render.js b/packages/rax/src/__tests__/render.js index ceea13ff8e..5abbcfcd52 100644 --- a/packages/rax/src/__tests__/render.js +++ b/packages/rax/src/__tests__/render.js @@ -66,12 +66,24 @@ describe('render', () => { expect(instance1 === instance2).toBe(true); }); - it('should reuse markup if rendering to the same target twice', function() { + it('should trigger afterRender twice when render to the same target twice', () => { + let beforeRenderCount = 0; + let afterRenderCount = 0; let container = createNodeElement('container'); - let instance1 = render(
, container); - let instance2 = render(
, container); + Host.driver = Object.assign({}, Host.driver, { + beforeRender() { + beforeRenderCount += 1; + }, + afterRender() { + afterRenderCount += 1; + }, + }); - expect(instance1 === instance2).toBe(true); + render(
, container); + render(, container); + + expect(beforeRenderCount).toBe(2); + expect(afterRenderCount).toBe(2); }); it('should not throw error when have callback and options is null', function(done) { diff --git a/packages/rax/src/vdom/instance.js b/packages/rax/src/vdom/instance.js index baac7d6727..7ec0cf5c49 100644 --- a/packages/rax/src/vdom/instance.js +++ b/packages/rax/src/vdom/instance.js @@ -70,6 +70,10 @@ export default { prevRootInstance[INTERNAL].__penddingContext = parentContext; } prevRootInstance.__update(element); + + // After render callback + driver.afterRender && driver.afterRender(renderOptions); + return prevRootInstance; } @@ -78,6 +82,7 @@ export default { let defaultContext = parentContext || {}; let rootInstance = renderedComponent.__mountComponent(container, parent, defaultContext); this.set(container, rootInstance); + // Mount new element through update queue avoid when there is in rendering phase rootInstance.__update(element); @@ -87,7 +92,6 @@ export default { if (process.env.NODE_ENV !== 'production') { // Devtool render new root hook Host.reconciler.renderNewRootComponent(rootInstance[INTERNAL][RENDERED_COMPONENT]); - Host.measurer && Host.measurer.afterRender(); }