@tamagui/use-did-finish-ssr 1.46.2 → 1.47.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.
package/dist/cjs/index.js CHANGED
@@ -22,29 +22,20 @@ __export(src_exports, {
22
22
  useDidFinishSSR: () => useDidFinishSSR
23
23
  });
24
24
  module.exports = __toCommonJS(src_exports);
25
- var import_constants = require("@tamagui/constants");
26
25
  var import_react = require("react");
27
- function useDidFinishSSR() {
28
- if (import_constants.isServer) {
29
- return false;
30
- }
31
- const [did, setDid] = (0, import_react.useState)(false);
32
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
33
- (0, import_react.startTransition)(() => {
34
- setDid(true);
35
- });
36
- }, []);
37
- return did;
26
+ const emptyFn = () => {
27
+ };
28
+ const emptyFnFn = () => emptyFn;
29
+ function useDidFinishSSR(value) {
30
+ return (0, import_react.useSyncExternalStore)(
31
+ emptyFnFn,
32
+ () => value == void 0 ? true : value,
33
+ () => false
34
+ );
38
35
  }
39
36
  function useClientValue(value) {
40
- if (import_constants.isServer) {
41
- return;
42
- }
43
- const [v, setV] = (0, import_react.useState)(void 0);
44
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
45
- setV(value);
46
- }, []);
47
- return v;
37
+ const done = useDidFinishSSR();
38
+ return !done ? void 0 : typeof value === "function" ? value() : value;
48
39
  }
49
40
  // Annotate the CommonJS export names for ESM import in node:
50
41
  0 && (module.exports = {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAoD;AACpD,mBAA0C;AAEnC,SAAS,kBAAkB;AAEhC,MAAI,2BAAU;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,KAAK,MAAM,QAAI,uBAAkB,KAAK;AAE7C,kDAA0B,MAAM;AAC9B,sCAAgB,MAAM;AACpB,aAAO,IAAI;AAAA,IACb,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAIO,SAAS,eACd,OACoC;AACpC,MAAI,2BAAU;AACZ;AAAA,EACF;AAEA,QAAM,CAAC,GAAG,IAAI,QAAI,uBAA6C,MAAS;AAExE,kDAA0B,MAAM;AAE9B,SAAK,KAAK;AAAA,EACZ,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AAErC,MAAM,UAAU,MAAM;AAAC;AACvB,MAAM,YAAY,MAAM;AAEjB,SAAS,gBAAyC,OAAsB;AAC7E,aAAO;AAAA,IACL;AAAA,IACA,MAAO,SAAS,SAAY,OAAO;AAAA,IACnC,MAAM;AAAA,EACR;AACF;AAIO,SAAS,eACd,OACoC;AACpC,QAAM,OAAO,gBAAgB;AAC7B,SAAO,CAAC,OAAO,SAAY,OAAO,UAAU,aAAa,MAAM,IAAI;AACrE;",
5
5
  "names": []
6
6
  }
package/dist/esm/index.js CHANGED
@@ -1,26 +1,17 @@
1
- import { isServer, useIsomorphicLayoutEffect } from "@tamagui/constants";
2
- import { startTransition, useState } from "react";
3
- function useDidFinishSSR() {
4
- if (isServer) {
5
- return false;
6
- }
7
- const [did, setDid] = useState(false);
8
- useIsomorphicLayoutEffect(() => {
9
- startTransition(() => {
10
- setDid(true);
11
- });
12
- }, []);
13
- return did;
1
+ import { useSyncExternalStore } from "react";
2
+ const emptyFn = () => {
3
+ };
4
+ const emptyFnFn = () => emptyFn;
5
+ function useDidFinishSSR(value) {
6
+ return useSyncExternalStore(
7
+ emptyFnFn,
8
+ () => value == void 0 ? true : value,
9
+ () => false
10
+ );
14
11
  }
15
12
  function useClientValue(value) {
16
- if (isServer) {
17
- return;
18
- }
19
- const [v, setV] = useState(void 0);
20
- useIsomorphicLayoutEffect(() => {
21
- setV(value);
22
- }, []);
23
- return v;
13
+ const done = useDidFinishSSR();
14
+ return !done ? void 0 : typeof value === "function" ? value() : value;
24
15
  }
25
16
  export {
26
17
  useClientValue,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "mappings": "AAAA,SAAS,UAAU,iCAAiC;AACpD,SAAS,iBAAiB,gBAAgB;AAEnC,SAAS,kBAAkB;AAEhC,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,KAAK,MAAM,IAAI,SAAkB,KAAK;AAE7C,4BAA0B,MAAM;AAC9B,oBAAgB,MAAM;AACpB,aAAO,IAAI;AAAA,IACb,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAIO,SAAS,eACd,OACoC;AACpC,MAAI,UAAU;AACZ;AAAA,EACF;AAEA,QAAM,CAAC,GAAG,IAAI,IAAI,SAA6C,MAAS;AAExE,4BAA0B,MAAM;AAE9B,SAAK,KAAK;AAAA,EACZ,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
4
+ "mappings": "AAAA,SAAS,4BAA4B;AAErC,MAAM,UAAU,MAAM;AAAC;AACvB,MAAM,YAAY,MAAM;AAEjB,SAAS,gBAAyC,OAAsB;AAC7E,SAAO;AAAA,IACL;AAAA,IACA,MAAO,SAAS,SAAY,OAAO;AAAA,IACnC,MAAM;AAAA,EACR;AACF;AAIO,SAAS,eACd,OACoC;AACpC,QAAM,OAAO,gBAAgB;AAC7B,SAAO,CAAC,OAAO,SAAY,OAAO,UAAU,aAAa,MAAM,IAAI;AACrE;",
5
5
  "names": []
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/use-did-finish-ssr",
3
- "version": "1.46.2",
3
+ "version": "1.47.0",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -26,10 +26,10 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@tamagui/constants": "1.46.2"
29
+ "@tamagui/constants": "1.47.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@tamagui/build": "1.46.2",
32
+ "@tamagui/build": "1.47.0",
33
33
  "react": "^18.2.0"
34
34
  },
35
35
  "peerDependencies": {
package/src/index.ts CHANGED
@@ -1,21 +1,14 @@
1
- import { isServer, useIsomorphicLayoutEffect } from '@tamagui/constants'
2
- import { startTransition, useState } from 'react'
1
+ import { useSyncExternalStore } from 'react'
3
2
 
4
- export function useDidFinishSSR() {
5
- // conditional hook because it never changes if already true
6
- if (isServer) {
7
- return false
8
- }
3
+ const emptyFn = () => {}
4
+ const emptyFnFn = () => emptyFn
9
5
 
10
- const [did, setDid] = useState<boolean>(false)
11
-
12
- useIsomorphicLayoutEffect(() => {
13
- startTransition(() => {
14
- setDid(true)
15
- })
16
- }, [])
17
-
18
- return did
6
+ export function useDidFinishSSR<A extends any = boolean>(value?: A): A | false {
7
+ return useSyncExternalStore(
8
+ emptyFnFn,
9
+ () => (value == undefined ? true : value),
10
+ () => false as any
11
+ )
19
12
  }
20
13
 
21
14
  type FunctionOrValue<Value> = Value extends () => infer X ? X : Value
@@ -23,16 +16,6 @@ type FunctionOrValue<Value> = Value extends () => infer X ? X : Value
23
16
  export function useClientValue<Value extends any>(
24
17
  value?: Value
25
18
  ): FunctionOrValue<Value> | undefined {
26
- if (isServer) {
27
- return
28
- }
29
-
30
- const [v, setV] = useState<FunctionOrValue<Value> | undefined>(undefined)
31
-
32
- useIsomorphicLayoutEffect(() => {
33
- // @ts-expect-error (this works with a function)
34
- setV(value)
35
- }, [])
36
-
37
- return v
19
+ const done = useDidFinishSSR()
20
+ return !done ? undefined : typeof value === 'function' ? value() : value
38
21
  }
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare function useDidFinishSSR(): boolean;
1
+ export declare function useDidFinishSSR<A extends any = boolean>(value?: A): A | false;
2
2
  type FunctionOrValue<Value> = Value extends () => infer X ? X : Value;
3
3
  export declare function useClientValue<Value extends any>(value?: Value): FunctionOrValue<Value> | undefined;
4
4
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,YAe9B;AAED,KAAK,eAAe,CAAC,KAAK,IAAI,KAAK,SAAS,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAErE,wBAAgB,cAAc,CAAC,KAAK,SAAS,GAAG,EAC9C,KAAK,CAAC,EAAE,KAAK,GACZ,eAAe,CAAC,KAAK,CAAC,GAAG,SAAS,CAapC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,wBAAgB,eAAe,CAAC,CAAC,SAAS,GAAG,GAAG,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAM7E;AAED,KAAK,eAAe,CAAC,KAAK,IAAI,KAAK,SAAS,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAErE,wBAAgB,cAAc,CAAC,KAAK,SAAS,GAAG,EAC9C,KAAK,CAAC,EAAE,KAAK,GACZ,eAAe,CAAC,KAAK,CAAC,GAAG,SAAS,CAGpC"}