Skip to content

Commit 4f48f1f

Browse files
authored
* 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
1 parent 24424cf commit 4f48f1f

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

packages/rax/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rax",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "A universal React-compatible render engine.",
55
"license": "BSD-3-Clause",
66
"main": "index.js",

packages/rax/src/__tests__/render.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,24 @@ describe('render', () => {
6666
expect(instance1 === instance2).toBe(true);
6767
});
6868

69-
it('should reuse markup if rendering to the same target twice', function() {
69+
it('should trigger afterRender twice when render to the same target twice', () => {
70+
let beforeRenderCount = 0;
71+
let afterRenderCount = 0;
7072
let container = createNodeElement('container');
71-
let instance1 = render(<div />, container);
72-
let instance2 = render(<div />, container);
73+
Host.driver = Object.assign({}, Host.driver, {
74+
beforeRender() {
75+
beforeRenderCount += 1;
76+
},
77+
afterRender() {
78+
afterRenderCount += 1;
79+
},
80+
});
7381

74-
expect(instance1 === instance2).toBe(true);
82+
render(<div />, container);
83+
render(<span />, container);
84+
85+
expect(beforeRenderCount).toBe(2);
86+
expect(afterRenderCount).toBe(2);
7587
});
7688

7789
it('should not throw error when have callback and options is null', function(done) {

packages/rax/src/vdom/instance.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export default {
7070
prevRootInstance[INTERNAL].__penddingContext = parentContext;
7171
}
7272
prevRootInstance.__update(element);
73+
74+
// After render callback
75+
driver.afterRender && driver.afterRender(renderOptions);
76+
7377
return prevRootInstance;
7478
}
7579

@@ -78,6 +82,7 @@ export default {
7882
let defaultContext = parentContext || {};
7983
let rootInstance = renderedComponent.__mountComponent(container, parent, defaultContext);
8084
this.set(container, rootInstance);
85+
8186
// Mount new element through update queue avoid when there is in rendering phase
8287
rootInstance.__update(element);
8388

@@ -87,7 +92,6 @@ export default {
8792
if (process.env.NODE_ENV !== 'production') {
8893
// Devtool render new root hook
8994
Host.reconciler.renderNewRootComponent(rootInstance[INTERNAL][RENDERED_COMPONENT]);
90-
9195
Host.measurer && Host.measurer.afterRender();
9296
}
9397

0 commit comments

Comments
 (0)