Skip to content

Commit

Permalink
release: rax@1.1.4 (#1953)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
imsobear authored Jul 14, 2020
1 parent 24424cf commit 4f48f1f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/rax/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 16 additions & 4 deletions packages/rax/src/__tests__/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<div />, container);
let instance2 = render(<div />, container);
Host.driver = Object.assign({}, Host.driver, {
beforeRender() {
beforeRenderCount += 1;
},
afterRender() {
afterRenderCount += 1;
},
});

expect(instance1 === instance2).toBe(true);
render(<div />, container);
render(<span />, container);

expect(beforeRenderCount).toBe(2);
expect(afterRenderCount).toBe(2);
});

it('should not throw error when have callback and options is null', function(done) {
Expand Down
6 changes: 5 additions & 1 deletion packages/rax/src/vdom/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export default {
prevRootInstance[INTERNAL].__penddingContext = parentContext;
}
prevRootInstance.__update(element);

// After render callback
driver.afterRender && driver.afterRender(renderOptions);

return prevRootInstance;
}

Expand All @@ -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);

Expand All @@ -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();
}

Expand Down

0 comments on commit 4f48f1f

Please sign in to comment.