diff --git a/hooks/src/index.js b/hooks/src/index.js index 41006eb624..b595584c1c 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -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 @@ -51,7 +49,6 @@ options._render = vnode => { if (oldBeforeRender) oldBeforeRender(vnode); currentComponent = vnode._component; - localIdCounter = 0; currentIndex = 0; const hooks = currentComponent.__hooks; @@ -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; diff --git a/hooks/test/browser/useId.test.js b/hooks/test/browser/useId.test.js index 4802f289a7..fbcd380191 100644 --- a/hooks/test/browser/useId.test.js +++ b/hooks/test/browser/useId.test.js @@ -52,12 +52,12 @@ describe('useId', () => { render(, scratch); expect(scratch.innerHTML).to.equal( - '
h
' + '
h
' ); render(, scratch); expect(scratch.innerHTML).to.equal( - '
h
' + '
h
' ); }); @@ -80,12 +80,12 @@ describe('useId', () => { render(, scratch); expect(scratch.innerHTML).to.equal( - '
hhh
' + '
hhh
' ); render(, scratch); expect(scratch.innerHTML).to.equal( - '
hhh
' + '
hhh
' ); }); });