Skip to content

Commit

Permalink
Fixes an issue where vNode has wrong flags after directClone. Resolve…
Browse files Browse the repository at this point in the history
…s Github #1426
  • Loading branch information
Havunen committed Dec 13, 2018
1 parent cf3776b commit d4f8981
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@
"@babel/preset-typescript": "^7.1.0",
"@types/history": "^4.7.2",
"@types/jest": "^23.3.10",
"@types/node": "^10.12.12",
"@types/node": "^10.12.14",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-plugin-inferno": "6.0.4",
"cli-table": "^0.3.1",
"colors": "^1.3.2",
"colors": "^1.3.3",
"concat-stream-es6": "0.0.1",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
Expand All @@ -100,7 +100,7 @@
"jest": "^23.6.0",
"jest-silent-reporter": "^0.1.1",
"jsdom": "13.0.0",
"lerna": "3.5.1",
"lerna": "3.6.0",
"lint-staged": "^8.1.0",
"madge": "^3.3.0",
"minimist": "^1.2.0",
Expand All @@ -111,17 +111,17 @@
"prettier": "^1.15.3",
"rimraf": "^2.6.2",
"rollup": "^0.67.4",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-buble": "^0.19.4",
"rollup-plugin-alias": "^1.5.1",
"rollup-plugin-babel": "^4.1.0",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-typescript2": "0.18.0",
"rollup-plugin-typescript2": "0.18.1",
"rollup-plugin-uglify": "^6.0.0",
"sinon": "^7.1.1",
"sinon": "^7.2.2",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.17.0",
"typescript": "3.2.1"
"typescript": "3.2.2"
}
}
24 changes: 24 additions & 0 deletions packages/inferno-hydrate/__tests__/hydrate.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { render, rerender, createRef, createPortal, createFragment, Component, Fragment } from 'inferno';
import { hydrate } from 'inferno-hydrate';
import { h } from 'inferno-hyperscript';
import sinon from 'sinon';
import { triggerEvent } from 'inferno-utils';
import { ChildFlags } from 'inferno-vnode-flags';
Expand Down Expand Up @@ -1251,4 +1252,27 @@ describe('rendering routine', () => {
expect(container.firstChild.firstChild.getAttribute('class')).toBe('bar');
});
});

it('Should not re-mount after hydrate render render, Github #1426', () => {

container.innerHTML = '<div><span>do not replace me</span></div>';

const span = container.firstChild.firstChild;

let vtree = h('div', [h('span', 'do not replace me')]);

hydrate(vtree, container);

expect(span).toBe(container.firstChild.firstChild);

render(vtree, container);

expect(span).toBe(container.firstChild.firstChild);

let vtree2 = h('div', [h('span', 'do not replace me')]);

render(vtree2, container);

expect(span).toBe(container.firstChild.firstChild);
});
});
3 changes: 2 additions & 1 deletion packages/inferno-hydrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"devDependencies": {
"inferno-create-element": "7.0.2",
"inferno-shared": "7.0.2",
"inferno-vnode-flags": "7.0.2"
"inferno-vnode-flags": "7.0.2",
"inferno-hyperscript": "7.0.2"
},
"rollup": {
"bundledDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,11 @@ describe('SSR Hydration Extended - (JSX)', () => {
expect(container.textContent).toBe('Okay!');
});

it('createTextVNode - Should handle empty textNodes correctly Github #1137', () => {
it('createTextVNode - Should handle empty textNodes correctly Github #1137 variation#3', () => {
const container = createContainerWithHTML('<span class="error"></span>');

const vNode = <span className="error">{createTextVNode('')}</span>;

expect(vNode.children).toEqual(createTextVNode(''));

hydrate(vNode, container); // This should create empty text node

expect(container.firstChild.firstChild).not.toBeNull();
Expand All @@ -200,7 +198,7 @@ describe('SSR Hydration Extended - (JSX)', () => {
expect(container.textContent).toBe('Okay!');
});

it('createTextVNode - Should handle empty textNodes correctly Github #1137 variation#2', () => {
it('createTextVNode - Should handle empty textNodes correctly Github #1137 variation#4', () => {
const container = createContainerWithHTML('<div><span class="error"></span></div>');

const vNode = (
Expand All @@ -209,8 +207,6 @@ describe('SSR Hydration Extended - (JSX)', () => {
</div>
);

expect(vNode.children.children).toEqual(createTextVNode(''));

hydrate(vNode, container); // This should create empty text node

expect(container.firstChild.firstChild.firstChild).not.toBeNull();
Expand Down
2 changes: 1 addition & 1 deletion packages/inferno-vnode-flags/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const enum VNodeFlags {
Component = ComponentFunction | ComponentClass | ComponentUnknown,
DOMRef = Element | Text | Void | Portal,
InUseOrNormalized = InUse | Normalized,
ClearInUseNormalized = ~InUseOrNormalized
ClearInUse = ~InUse
}

// Combinations are not possible, its bitwise only to reduce vNode size
Expand Down
2 changes: 1 addition & 1 deletion packages/inferno/src/core/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function cloneFragment(vNodeToClone) {
}

export function directClone(vNodeToClone: VNode): VNode {
const flags = vNodeToClone.flags & VNodeFlags.ClearInUseNormalized;
const flags = vNodeToClone.flags & VNodeFlags.ClearInUse;
let props = vNodeToClone.props;

if (flags & VNodeFlags.Component) {
Expand Down

0 comments on commit d4f8981

Please sign in to comment.