Skip to content

Commit

Permalink
fix(multishift): remove @reach/auto-id (#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue committed Mar 10, 2023
1 parent 2518cde commit 48ee2c2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-pianos-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'multishift': patch
---

Remove maintained `@reach/auto-id` from dependencies.
1 change: 0 additions & 1 deletion packages/multishift/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
],
"dependencies": {
"@babel/runtime": "^7.13.10",
"@reach/auto-id": "^0.18.0",
"@remirror/core-helpers": "^2.0.1",
"@remirror/core-types": "^2.0.4",
"@seznam/compose-react-refs": "^1.0.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/multishift/src/multishift-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useId } from '@reach/auto-id';
import { setStatus } from 'a11y-status';
import type { DependencyList, Dispatch, EffectCallback, MutableRefObject } from 'react';
import { useEffect, useReducer, useRef } from 'react';
Expand All @@ -23,6 +22,7 @@ import {
getInitialStateProps,
isOrContainsNode,
} from './multishift-utils';
import { useId } from './use-id';

/**
* Creates the reducer for managing the multishift internal state.
Expand Down
35 changes: 35 additions & 0 deletions packages/multishift/src/use-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from 'react';

const useIsomorphicLayoutEffect =
typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect;

let count = 0;
const genId = () => `multishift-id-${count++}`;

let serverHandoffComplete = false;

function useReact17Id() {
const [id, setId] = React.useState(() => (serverHandoffComplete ? genId() : undefined));

useIsomorphicLayoutEffect(() => {
if (id == null) {
setId(genId());
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

React.useEffect(() => {
if (!serverHandoffComplete) {
serverHandoffComplete = true;
}
}, []);

return id;
}

// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
const useReact18Id = (React as any)['useId'.toString()] as () => string;

const useId = useReact18Id || useReact17Id;

export { useId };
21 changes: 0 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 48ee2c2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://remirror.io as production
🚀 Deployed on https://640ba86fd8fc9d07cb28ce55--remirror.netlify.app

Please sign in to comment.