@frontegg/react-hooks 5.18.2 → 5.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +12 -6
  2. package/node/index.js +12 -6
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -27,7 +27,15 @@ const setLoading = (loading) => {
27
27
  const HideChildrenIfFronteggRoutes = ({ children, basename }) => {
28
28
  const routes = useAuthRoutes();
29
29
  const uriRef = useRef(window.location.pathname);
30
+ const animationFrameRef = useRef(0);
30
31
  const [uri, setUri] = useState(window.location.pathname);
32
+ const checker = () => {
33
+ if (uriRef.current !== window.location.pathname) {
34
+ uriRef.current = window.location.pathname;
35
+ setUri(document.location.pathname);
36
+ }
37
+ animationFrameRef.current = window.requestAnimationFrame(checker);
38
+ };
31
39
  useEffect(() => {
32
40
  document.addEventListener('frontegg_onRedirectTo_fired', () => {
33
41
  if (uriRef.current !== window.location.pathname) {
@@ -41,12 +49,10 @@ const HideChildrenIfFronteggRoutes = ({ children, basename }) => {
41
49
  setUri(document.location.pathname);
42
50
  }
43
51
  });
44
- setInterval(() => {
45
- if (uriRef.current !== window.location.pathname) {
46
- uriRef.current = window.location.pathname;
47
- setUri(document.location.pathname);
48
- }
49
- }, 50);
52
+ animationFrameRef.current = window.requestAnimationFrame(checker);
53
+ return () => {
54
+ window.cancelAnimationFrame(animationFrameRef.current);
55
+ };
50
56
  }, [setUri]);
51
57
  const calculatedBasename = basename ? (basename.endsWith('/') ? basename.substring(0, basename.length - 1) : '') : '';
52
58
  const checkRoutes = __rest(routes, ["authenticatedUrl", "signUpSuccessUrl"]);
package/node/index.js CHANGED
@@ -32,7 +32,15 @@ const setLoading = (loading) => {
32
32
  const HideChildrenIfFronteggRoutes = ({ children, basename }) => {
33
33
  const routes = roles.useAuthRoutes();
34
34
  const uriRef = React.useRef(window.location.pathname);
35
+ const animationFrameRef = React.useRef(0);
35
36
  const [uri, setUri] = React.useState(window.location.pathname);
37
+ const checker = () => {
38
+ if (uriRef.current !== window.location.pathname) {
39
+ uriRef.current = window.location.pathname;
40
+ setUri(document.location.pathname);
41
+ }
42
+ animationFrameRef.current = window.requestAnimationFrame(checker);
43
+ };
36
44
  React.useEffect(() => {
37
45
  document.addEventListener('frontegg_onRedirectTo_fired', () => {
38
46
  if (uriRef.current !== window.location.pathname) {
@@ -46,12 +54,10 @@ const HideChildrenIfFronteggRoutes = ({ children, basename }) => {
46
54
  setUri(document.location.pathname);
47
55
  }
48
56
  });
49
- setInterval(() => {
50
- if (uriRef.current !== window.location.pathname) {
51
- uriRef.current = window.location.pathname;
52
- setUri(document.location.pathname);
53
- }
54
- }, 50);
57
+ animationFrameRef.current = window.requestAnimationFrame(checker);
58
+ return () => {
59
+ window.cancelAnimationFrame(animationFrameRef.current);
60
+ };
55
61
  }, [setUri]);
56
62
  const calculatedBasename = basename ? (basename.endsWith('/') ? basename.substring(0, basename.length - 1) : '') : '';
57
63
  const checkRoutes = tslib.__rest(routes, ["authenticatedUrl", "signUpSuccessUrl"]);
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@frontegg/react-hooks",
3
3
  "libName": "FronteggReactHooks",
4
- "version": "5.18.2",
4
+ "version": "5.20.1",
5
5
  "author": "Frontegg LTD",
6
6
  "main": "./node/index.js",
7
7
  "module": "./index.js",
8
8
  "types": "./index.d.ts",
9
9
  "dependencies": {
10
- "@frontegg/redux-store": "5.18.2",
10
+ "@frontegg/redux-store": "5.20.1",
11
11
  "react-redux": "^7.x"
12
12
  }
13
13
  }