@foxglove/embed-react 0.69.0 → 0.70.0

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.
@@ -1,3 +1,7 @@
1
- /** Call _warn_ if a given value changes twice within 200 ms */
1
+ /**
2
+ * Call `warn` if `value` changes twice within 200 ms, and return `value` unchanged.
3
+ *
4
+ * The comparison runs after commit, so a render React discards does not count toward the rate.
5
+ */
2
6
  export declare function useShouldNotChangeOften<T>(value: T, warn: () => void): T;
3
7
  //# sourceMappingURL=useShouldNotChangeOften.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useShouldNotChangeOften.d.ts","sourceRoot":"","sources":["../src/useShouldNotChangeOften.ts"],"names":[],"mappings":"AAKA,+DAA+D;AAC/D,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,CAAC,CAqBxE"}
1
+ {"version":3,"file":"useShouldNotChangeOften.d.ts","sourceRoot":"","sources":["../src/useShouldNotChangeOften.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,CAAC,CAkBxE"}
@@ -1,26 +1,30 @@
1
1
  // This file is copied from @foxglove/viz/hooks/useShouldNotChangeOften.ts
2
2
  // We copy the file to avoid depending on the viz package.
3
- import { useRef } from "react";
4
- /** Call _warn_ if a given value changes twice within 200 ms */
3
+ //
4
+ // The viz copy additionally compiles itself out of production builds. This one does not: it is
5
+ // called twice in one component rather than once per layout selector, and this package ships
6
+ // unbundled, with no `process` binding to test and no bundler to fold the branch away.
7
+ import { useLayoutEffect, useRef } from "react";
8
+ /**
9
+ * Call `warn` if `value` changes twice within 200 ms, and return `value` unchanged.
10
+ *
11
+ * The comparison runs after commit, so a render React discards does not count toward the rate.
12
+ */
5
13
  export function useShouldNotChangeOften(value, warn) {
6
14
  const prev = useRef(value);
7
15
  const prevPrev = useRef(value);
8
16
  const lastTime = useRef(Date.now());
9
- if (
10
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
11
- value !== prev.current &&
12
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
13
- prev.current !== prevPrev.current &&
14
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
15
- Date.now() - lastTime.current < 200) {
16
- warn();
17
- }
18
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
19
- prevPrev.current = prev.current;
20
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
21
- prev.current = value;
22
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
23
- lastTime.current = Date.now();
17
+ useLayoutEffect(() => {
18
+ const now = Date.now();
19
+ if (value !== prev.current &&
20
+ prev.current !== prevPrev.current &&
21
+ now - lastTime.current < 200) {
22
+ warn();
23
+ }
24
+ prevPrev.current = prev.current;
25
+ prev.current = value;
26
+ lastTime.current = now;
27
+ });
24
28
  return value;
25
29
  }
26
30
  //# sourceMappingURL=useShouldNotChangeOften.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useShouldNotChangeOften.js","sourceRoot":"","sources":["../src/useShouldNotChangeOften.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,0DAA0D;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,+DAA+D;AAC/D,MAAM,UAAU,uBAAuB,CAAI,KAAQ,EAAE,IAAgB;IACnE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,MAAM,CAAS,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5C;IACE,yFAAyF;IACzF,KAAK,KAAK,IAAI,CAAC,OAAO;QACtB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O,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxglove/embed-react",
3
- "version": "0.69.0",
3
+ "version": "0.70.0",
4
4
  "keywords": [
5
5
  "foxglove",
6
6
  "react",
@@ -31,7 +31,7 @@
31
31
  "prepack": "yarn build"
32
32
  },
33
33
  "dependencies": {
34
- "@foxglove/embed": "0.69.0"
34
+ "@foxglove/embed": "0.70.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/react": "19.2.18",
@@ -1,28 +1,33 @@
1
1
  // This file is copied from @foxglove/viz/hooks/useShouldNotChangeOften.ts
2
2
  // We copy the file to avoid depending on the viz package.
3
+ //
4
+ // The viz copy additionally compiles itself out of production builds. This one does not: it is
5
+ // called twice in one component rather than once per layout selector, and this package ships
6
+ // unbundled, with no `process` binding to test and no bundler to fold the branch away.
3
7
 
4
- import { useRef } from "react";
8
+ import { useLayoutEffect, useRef } from "react";
5
9
 
6
- /** Call _warn_ if a given value changes twice within 200 ms */
10
+ /**
11
+ * Call `warn` if `value` changes twice within 200 ms, and return `value` unchanged.
12
+ *
13
+ * The comparison runs after commit, so a render React discards does not count toward the rate.
14
+ */
7
15
  export function useShouldNotChangeOften<T>(value: T, warn: () => void): T {
8
16
  const prev = useRef(value);
9
17
  const prevPrev = useRef(value);
10
18
  const lastTime = useRef<number>(Date.now());
11
- if (
12
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
13
- value !== prev.current &&
14
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
15
- prev.current !== prevPrev.current &&
16
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
17
- Date.now() - lastTime.current < 200
18
- ) {
19
- warn();
20
- }
21
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
22
- prevPrev.current = prev.current;
23
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
24
- prev.current = value;
25
- // eslint-disable-next-line react-hooks/refs -- Pre-existing violation, not yet migrated.
26
- lastTime.current = Date.now();
19
+ useLayoutEffect(() => {
20
+ const now = Date.now();
21
+ if (
22
+ value !== prev.current &&
23
+ prev.current !== prevPrev.current &&
24
+ now - lastTime.current < 200
25
+ ) {
26
+ warn();
27
+ }
28
+ prevPrev.current = prev.current;
29
+ prev.current = value;
30
+ lastTime.current = now;
31
+ });
27
32
  return value;
28
33
  }