Skip to content

Commit

Permalink
fix compat hydration (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Dec 25, 2019
1 parent 71425ff commit 8b8de40
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compat/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Children } from './Children';
import { Suspense, lazy } from './suspense';
import { SuspenseList } from './suspense-list';
import { createPortal } from './portals';
import { render, REACT_ELEMENT_TYPE } from './render';
import { hydrate, render, REACT_ELEMENT_TYPE } from './render';

const version = '16.8.0'; // trick libraries to think we are react

Expand Down Expand Up @@ -100,7 +100,7 @@ export {
version,
Children,
render,
render as hydrate,
hydrate,
unmountComponentAtNode,
createPortal,
createElement,
Expand Down
4 changes: 4 additions & 0 deletions compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function render(vnode, parent, callback) {
}
}

return hydrate(vnode, parent, callback);
}

export function hydrate(vnode, parent, callback) {
preactRender(vnode, parent);
if (typeof callback === 'function') callback();

Expand Down
25 changes: 25 additions & 0 deletions compat/test/browser/hydrate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { hydrate } from 'preact/compat';
import { setupScratch, teardown } from '../../../test/_util/helpers';

describe('compat hydrate', () => {
/** @type {HTMLDivElement} */
let scratch;

beforeEach(() => {
scratch = setupScratch();
});

afterEach(() => {
teardown(scratch);
});

it('should render react-style jsx', () => {
const input = document.createElement('input');
scratch.appendChild(input);
input.focus();
expect(document.activeElement).to.equal(input);

hydrate(<input />, scratch);
expect(document.activeElement).to.equal(input);
});
});

0 comments on commit 8b8de40

Please sign in to comment.