Skip to content

Commit

Permalink
Drop useId hashing as it's not needed anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Oct 25, 2022
1 parent 8cdab51 commit d4c2063
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
11 changes: 1 addition & 10 deletions hooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,6 @@ export function useErrorBoundary(cb) {
];
}

function hash(s) {
let h = 0,
i = s.length;
while (i > 0) {
h = ((h << 5) - h + s.charCodeAt(--i)) | 0;
}
return h;
}

export function useId() {
const state = getHookState(currentIndex++, 11);
if (!state._value) {
Expand All @@ -401,7 +392,7 @@ export function useId() {

// Increase the current component depth pointer
ids[i - 1]++;
state._value = 'P' + hash(ids.join('')) + currentIndex;
state._value = 'P' + ids.join('') + currentIndex;
}

return state._value;
Expand Down
16 changes: 8 additions & 8 deletions hooks/test/browser/useId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ describe('useId', () => {

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P481"><div id="P491"><span id="P502">h</span></div></div>'
'<div id="P01"><div id="P11"><span id="P22">h</span></div></div>'
);

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P481"><div id="P491"><span id="P502">h</span></div></div>'
'<div id="P01"><div id="P11"><span id="P22">h</span></div></div>'
);
});

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

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P481"><span id="P491">h</span><span id="P501">h</span><span id="P511">h</span></div>'
'<div id="P01"><span id="P11">h</span><span id="P21">h</span><span id="P31">h</span></div>'
);

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P481"><span id="P491">h</span><span id="P501">h</span><span id="P511">h</span></div>'
'<div id="P01"><span id="P11">h</span><span id="P21">h</span><span id="P31">h</span></div>'
);
});

Expand Down Expand Up @@ -121,13 +121,13 @@ describe('useId', () => {

render(<Comp />, scratch);
expect(scratch.innerHTML).to.equal(
'<div id="P481"><div><span id="P15671">h</span></div></div>'
'<div id="P01"><div><span id="P011">h</span></div></div>'
);

set(true);
rerender();
expect(scratch.innerHTML).to.equal(
'<div id="P481"><div><span id="P15671">h</span><span id="P15981">h</span></div></div>'
'<div id="P01"><div><span id="P011">h</span><span id="P021">h</span></div></div>'
);
});

Expand Down Expand Up @@ -350,7 +350,7 @@ describe('useId', () => {
}

render(<App />, scratch);
expect(scratch.innerHTML).to.equal('<div><p>P481</p><p>P15671</p></div>');
expect(scratch.innerHTML).to.equal('<div><p>P01</p><p>P011</p></div>');
});

it('should skip over HTML', () => {
Expand All @@ -376,7 +376,7 @@ describe('useId', () => {
}

render(<App />, scratch);
expect(ids).to.deep.equal(['P491', 'P501']);
expect(ids).to.deep.equal(['P11', 'P21']);
});

it('should reset for each renderToString roots', () => {
Expand Down

0 comments on commit d4c2063

Please sign in to comment.