Skip to content

Commit c1339af

Browse files
authored
Merge pull request #163 from developit/fix-standalone-render
Fix render() in standalone build (fixes #159)
2 parents 86a7236 + b6b4d53 commit c1339af

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/integrations/preact/standalone.mjs

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
* limitations under the License.
1212
*/
1313

14-
import { h, Component, createContext, render as preactRender } from 'preact';
14+
import { h, Component, createContext, render } from 'preact';
1515
import { useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue } from 'preact/hooks';
1616
import htm from '../../index.mjs';
1717

18-
function render(tree, parent) {
19-
preactRender(tree, parent, parent.firstElementChild);
20-
}
21-
2218
const html = htm.bind(h);
2319

2420
export { h, html, render, Component, createContext, useState, useReducer, useEffect, useLayoutEffect, useRef, useImperativeHandle, useMemo, useCallback, useContext, useDebugValue };

test/preact.test.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import { html, Component, render } from 'htm/preact';
1515

16+
const sleep = ms => new Promise(r => setTimeout(r, ms));
17+
1618
describe('htm/preact', () => {
1719
const scratch = document.createElement('div');
1820
document.body.appendChild(scratch);
@@ -57,13 +59,11 @@ describe('htm/preact', () => {
5759
expect(scratch.innerHTML).toBe(fullHtml.replace('jason', 'tom'));
5860
});
5961

60-
test('state update re-renders', done => {
62+
test('state update re-renders', async () => {
6163
document.querySelector('button').click();
6264
document.querySelector('button').click();
63-
setTimeout(() => {
64-
expect(scratch.innerHTML).toBe(fullHtml.replace('jason', 'tom').replace(/\b0\b/g, '2'));
65-
done();
66-
});
65+
await sleep(1);
66+
expect(scratch.innerHTML).toBe(fullHtml.replace('jason', 'tom').replace(/\b0\b/g, '2'));
6767
});
6868

6969
test('preserves case', () => {

0 commit comments

Comments
 (0)