Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jul 3, 2022
1 parent 3f741ed commit 186f5da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 1 addition & 4 deletions hooks/src/index.js
Expand Up @@ -26,8 +26,6 @@ let oldBeforeUnmount = options.unmount;
const RAF_TIMEOUT = 100;
let prevRaf;

let localIdCounter = 0;

options._diff = vnode => {
if (vnode.type === Fragment) {
// Skip so we don't have to ensure wrapping fragments in RTS and prepass
Expand All @@ -51,7 +49,6 @@ options._render = vnode => {
if (oldBeforeRender) oldBeforeRender(vnode);

currentComponent = vnode._component;
localIdCounter = 0;
currentIndex = 0;

const hooks = currentComponent.__hooks;
Expand Down Expand Up @@ -342,7 +339,7 @@ function hash(str) {
export function useId() {
const state = getHookState(currentIndex++, 11);
if (!state._value) {
state._value = 'P' + hash(currentComponent._vnode._mask) + localIdCounter++;
state._value = 'P' + hash(currentComponent._vnode._mask + currentIndex);
}

return state._value;
Expand Down
8 changes: 4 additions & 4 deletions hooks/test/browser/useId.test.js
Expand Up @@ -52,12 +52,12 @@ describe('useId', () => {

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P11590"><div id="P1171070"><span id="P1171071">h</span></div></div>'
'<div id="P117108"><div id="P11827856"><span id="P11827857">h</span></div></div>'
);

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P11590"><div id="P1171070"><span id="P1171071">h</span></div></div>'
'<div id="P117108"><div id="P11827856"><span id="P11827857">h</span></div></div>'
);
});

Expand All @@ -80,12 +80,12 @@ describe('useId', () => {

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P11590"><span id="P1171070">h</span><span id="P1171080">h</span><span id="P1171090">h</span></div>'
'<div id="P117108"><span id="P11827856">h</span><span id="P11827957">h</span><span id="P11828058">h</span></div>'
);

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P11590"><span id="P1171070">h</span><span id="P1171080">h</span><span id="P1171090">h</span></div>'
'<div id="P117108"><span id="P11827856">h</span><span id="P11827957">h</span><span id="P11828058">h</span></div>'
);
});
});

0 comments on commit 186f5da

Please sign in to comment.