Skip to content

Commit fe23841

Browse files
committed
retain masks across useId invocations
1 parent 899e9d9 commit fe23841

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

hooks/src/index.js

+9
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

+23
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
});

0 commit comments

Comments
 (0)