@rpcbase/client 0.251.0 → 0.253.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/hooks.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/hooks"
package/instrument.ts CHANGED
@@ -15,23 +15,23 @@ if (isProduction) {
15
15
 
16
16
 
17
17
  if (isProduction) {
18
- if (!import.meta.env.RB_PUBLIC_POSTHOG_KEY) {
18
+ if (import.meta.env.RB_PUBLIC_POSTHOG_KEY) {
19
+ posthog.init(import.meta.env.RB_PUBLIC_POSTHOG_KEY, {
20
+ api_host: "/ingest",
21
+ // request_
22
+ ui_host: "https://eu.posthog.com",
23
+ person_profiles: "always",
24
+ session_recording: {
25
+ maskAllInputs: false
26
+ },
27
+ capture_pageview: isProduction,
28
+ autocapture: isProduction,
29
+ disable_session_recording: !isProduction,
30
+ })
31
+ } else {
19
32
  console.warn("missing POSTHOG_KEY")
20
- return
21
33
  }
22
34
 
23
- posthog.init(import.meta.env.RB_PUBLIC_POSTHOG_KEY, {
24
- api_host: "/ingest",
25
- // request_
26
- ui_host: "https://eu.posthog.com",
27
- person_profiles: "always",
28
- session_recording: {
29
- maskAllInputs: false
30
- },
31
- capture_pageview: isProduction,
32
- autocapture: isProduction,
33
- disable_session_recording: !isProduction,
34
- })
35
35
 
36
36
  } else {
37
37
  console.info("ℹ️ Not initializing posthog in development")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.251.0",
3
+ "version": "0.253.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "scripts": {
@@ -14,6 +14,7 @@
14
14
  "files": [
15
15
  "package.json",
16
16
  "./instrument.ts",
17
+ "./hooks.ts",
17
18
  "src/**/*"
18
19
  ],
19
20
  "output": [],
@@ -28,7 +29,10 @@
28
29
  "dependencies": {
29
30
  "@sentry/react": "9.15.0",
30
31
  "@sentry/tracing": "7.120.3",
31
- "axios": "1.9.0"
32
+ "axios": "1.9.0",
33
+ "fast-equals": "5.2.2",
34
+ "lodash": "4.17.21",
35
+ "react-use": "17.6.0"
32
36
  },
33
37
  "devDependencies": {}
34
38
  }
@@ -0,0 +1 @@
1
+ export * from "./useThrottledMeasure"
@@ -0,0 +1,47 @@
1
+ import {useState, useEffect, useRef, useCallback} from "react"
2
+ import useMeasure from "react-use/lib/useMeasure"
3
+ import _throttle from "lodash/throttle"
4
+ import { isEqual } from "fast-equals"
5
+
6
+
7
+ const DEFAULT_THROTTLE_TIME = 16
8
+
9
+ export const useThrottledMeasure = (throttleDuration = DEFAULT_THROTTLE_TIME) => {
10
+ const hasInitialMeasure = useRef(false)
11
+
12
+ const [ref, measuredRect] = useMeasure()
13
+ const [rect, setRect] = useState(() => {
14
+ return {x: 0, y: 0, width: 0, height: 0, top: 0, left: 0, bottom: 0, right: 0}
15
+ })
16
+
17
+ const throttledSetRect = useCallback(
18
+ _throttle(
19
+ (newRect) => {
20
+ setRect((current) => {
21
+ return isEqual(current, newRect) ? current : newRect
22
+ })
23
+ },
24
+ throttleDuration,
25
+ {leading: true, trailing: true},
26
+ ),
27
+ [throttleDuration],
28
+ )
29
+
30
+ useEffect(() => {
31
+ if (measuredRect.width > 0 && !hasInitialMeasure.current) {
32
+ hasInitialMeasure.current = true
33
+ setRect((current) => {
34
+ return isEqual(current, measuredRect) ? current : measuredRect
35
+ })
36
+ return
37
+ }
38
+
39
+ throttledSetRect(measuredRect)
40
+
41
+ return () => {
42
+ throttledSetRect.cancel()
43
+ }
44
+ }, [measuredRect, throttledSetRect])
45
+
46
+ return [ref, rect]
47
+ }