@jobber/components-native 0.116.1 → 0.116.2

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.
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.116.1",
3
+ "version": "0.116.2",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -125,5 +125,5 @@
125
125
  "react-native-screens": ">=4.18.0",
126
126
  "react-native-svg": ">=12.0.0"
127
127
  },
128
- "gitHead": "d324e138d0e3c27cf0e54dac5d40b2c2d7e9ab82"
128
+ "gitHead": "028f5c6483614c4409dbb96015b0d1b00cea1eb7"
129
129
  }
@@ -0,0 +1,28 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import uuid from "react-native-uuid";
3
+ import { useTokenGenerator } from "./useTokenGenerator";
4
+
5
+ describe("useTokenGenerator", () => {
6
+ it("generates tokens that its pattern matches", () => {
7
+ const { result } = renderHook(() => useTokenGenerator());
8
+ const [generateToken, tokenRegexp] = result.current;
9
+
10
+ const text = `${generateToken()} and ${generateToken()}`;
11
+
12
+ expect(text.match(tokenRegexp)).toHaveLength(2);
13
+ });
14
+
15
+ it("still renders late in a long session", () => {
16
+ // Exhaust react-native-uuid's argument-less v1() budget, which throws on
17
+ // its 10,000th call in a JS session.
18
+ for (let i = 0; i < 10_000; i++) {
19
+ try {
20
+ uuid.v1();
21
+ } catch {
22
+ break;
23
+ }
24
+ }
25
+
26
+ expect(() => renderHook(() => useTokenGenerator())).not.toThrow();
27
+ });
28
+ });
@@ -3,7 +3,7 @@ import uuid from "react-native-uuid";
3
3
 
4
4
  export function useTokenGenerator(): [() => string, RegExp] {
5
5
  let counter = 0;
6
- const [identifier] = useState(uuid.v1());
6
+ const [identifier] = useState(() => uuid.v4());
7
7
 
8
8
  return [
9
9
  () => `@__ELEMENT-${identifier}-${counter++}__@`,
@@ -0,0 +1,38 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import uuid from "react-native-uuid";
3
+ import { useFormController } from "./useFormController";
4
+
5
+ // react-native-uuid's v1() only resets its counter when given options, so its
6
+ // 10,000th argument-less call in a JS session throws. Exhaust it the way a long
7
+ // session with large forms does.
8
+ function exhaustUuidV1Budget() {
9
+ for (let i = 0; i < 10_000; i++) {
10
+ try {
11
+ uuid.v1();
12
+ } catch {
13
+ return;
14
+ }
15
+ }
16
+ }
17
+
18
+ describe("useFormController", () => {
19
+ it("keeps the generated field name stable across re-renders", () => {
20
+ const { result, rerender } = renderHook(() =>
21
+ useFormController({ value: "" }),
22
+ );
23
+ const initialName = result.current.field.name;
24
+
25
+ rerender({});
26
+
27
+ expect(initialName).toMatch(/^generatedName--/);
28
+ expect(result.current.field.name).toBe(initialName);
29
+ });
30
+
31
+ it("still renders unnamed fields late in a long session", () => {
32
+ exhaustUuidV1Budget();
33
+
34
+ expect(() =>
35
+ renderHook(() => useFormController({ value: "" })),
36
+ ).not.toThrow();
37
+ });
38
+ });
@@ -54,7 +54,7 @@ export function useFormController<T>({
54
54
  }
55
55
 
56
56
  function useControlName(name?: string): UseControllerReturn["field"]["name"] {
57
- const [identifier] = useState(uuid.v1());
57
+ const [identifier] = useState(() => uuid.v4());
58
58
  const prefix = `generatedName--${identifier}`;
59
59
 
60
60
  return `${name || prefix}` as const;