Skip to content

Commit fe0df55

Browse files
authored
Merge branch 'main' into multi-root-shared-commit
2 parents 5f6d63e + e1f0d3e commit fe0df55

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

compat/test/browser/events.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { render } from 'preact';
22
import {
33
setupScratch,
44
teardown,
5-
createEvent
5+
createEvent,
6+
supportsPassiveEvents
67
} from '../../../test/_util/helpers';
78

89
import React, { createElement } from 'preact/compat';
@@ -309,4 +310,24 @@ describe('preact/compat events', () => {
309310
scratch.firstChild.dispatchEvent(createEvent('focusout'));
310311
expect(spy).to.be.calledOnce;
311312
});
313+
314+
if (supportsPassiveEvents()) {
315+
it('should use capturing for event props ending with *Capture', () => {
316+
let click = sinon.spy();
317+
318+
render(
319+
<div onTouchMoveCapture={click}>
320+
<button type="button">Click me</button>
321+
</div>,
322+
scratch
323+
);
324+
325+
expect(proto.addEventListener).to.have.been.calledOnce;
326+
expect(proto.addEventListener).to.have.been.calledWithExactly(
327+
'touchmove',
328+
sinon.match.func,
329+
true
330+
);
331+
});
332+
}
312333
});

hooks/src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let oldBeforeRender = options._render;
2525
let oldAfterDiff = options.diffed;
2626
let oldCommit = options._commit;
2727
let oldBeforeUnmount = options.unmount;
28+
let oldRoot = options._root;
2829

2930
const RAF_TIMEOUT = 100;
3031
let prevRaf;
@@ -35,6 +36,14 @@ options._diff = vnode => {
3536
if (oldBeforeDiff) oldBeforeDiff(vnode);
3637
};
3738

39+
options._root = (vnode, parentDom) => {
40+
if (parentDom._children && parentDom._children._mask) {
41+
vnode._mask = parentDom._children._mask;
42+
}
43+
44+
if (oldRoot) oldRoot(vnode, parentDom);
45+
};
46+
3847
/** @type {(vnode: import('./internal').VNode) => void} */
3948
options._render = vnode => {
4049
if (oldBeforeRender) oldBeforeRender(vnode);

hooks/test/browser/useId.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,27 @@ describe('useId', () => {
433433
rerender();
434434
expect(first).not.to.equal(scratch.innerHTML);
435435
});
436+
437+
it('should return a unique id across invocations of render', () => {
438+
const Id = () => {
439+
const id = useId();
440+
return <div>My id is {id}</div>;
441+
};
442+
443+
const App = props => {
444+
return (
445+
<div>
446+
<Id />
447+
{props.secondId ? <Id /> : null}
448+
</div>
449+
);
450+
};
451+
452+
render(createElement(App, { secondId: false }), scratch);
453+
expect(scratch.innerHTML).to.equal('<div><div>My id is P0-0</div></div>');
454+
render(createElement(App, { secondId: true }), scratch);
455+
expect(scratch.innerHTML).to.equal(
456+
'<div><div>My id is P0-0</div><div>My id is P0-1</div></div>'
457+
);
458+
});
436459
});

src/diff/children.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,11 @@ function insert(parentVNode, oldDom, parentDom) {
367367
oldDom = parentVNode._dom;
368368
}
369369

370-
return oldDom && oldDom.nextSibling;
370+
do {
371+
oldDom = oldDom && oldDom.nextSibling;
372+
} while (oldDom != null && oldDom.nodeType === 8);
373+
374+
return oldDom;
371375
}
372376

373377
/**

src/diff/props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
5252
// Benchmark for comparison: https://esbench.com/bench/574c954bdb965b9a00965ac6
5353
else if (name[0] === 'o' && name[1] === 'n') {
5454
useCapture =
55-
name !== (name = name.replace(/(PointerCapture)$|Capture$/, '$1'));
55+
name !== (name = name.replace(/(PointerCapture)$|Capture$/i, '$1'));
5656

5757
// Infer correct casing for DOM built-in events:
5858
if (name.toLowerCase() in dom) name = name.toLowerCase().slice(2);

test/browser/hydrate.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ describe('hydrate()', () => {
5050
beforeEach(() => {
5151
scratch = setupScratch();
5252
attributesSpy = spyOnElementAttributes();
53+
clearLog();
5354
});
5455

5556
afterEach(() => {
5657
teardown(scratch);
57-
clearLog();
5858
});
5959

6060
it('should reuse existing DOM', () => {
@@ -92,6 +92,7 @@ describe('hydrate()', () => {
9292
scratch
9393
);
9494
expect(scratch.innerHTML).to.equal('<p><i>0</i><b>1</b></p>');
95+
expect(getLog()).to.deep.equal(['Comment.remove()']);
9596
});
9697

9798
it('should reuse existing DOM when given components', () => {
@@ -458,5 +459,13 @@ describe('hydrate()', () => {
458459
scratch.innerHTML = '<p>hello <!-- c -->foo</p>';
459460
hydrate(<p>hello {'foo'}</p>, scratch);
460461
expect(scratch.innerHTML).to.equal('<p>hello foo</p>');
462+
expect(getLog()).to.deep.equal(['Comment.remove()']);
463+
});
464+
465+
it('should skip over multiple comment nodes', () => {
466+
scratch.innerHTML = '<p>hello <!-- a --><!-- b -->foo</p>';
467+
hydrate(<p>hello {'foo'}</p>, scratch);
468+
expect(scratch.innerHTML).to.equal('<p>hello foo</p>');
469+
expect(getLog()).to.deep.equal(['Comment.remove()', 'Comment.remove()']);
461470
});
462471
});

0 commit comments

Comments
 (0)