@flareapp/react 2.6.0 → 2.8.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.
@@ -0,0 +1,86 @@
1
+ import { instrumentOnce, insulate, registerNavigationSource, resolveHref, routeName } from "@flareapp/js/browser";
2
+
3
+ //#region src/tanstack-router.ts
4
+ /**
5
+ * How long a held navigation root waits for `onResolved` before settling itself. Exported so the suite
6
+ * drives it instead of hardcoding the number; not part of the supported surface.
7
+ */
8
+ const STALE_NAVIGATION_TIMEOUT_MS = 5e3;
9
+ /**
10
+ * Trace a TanStack Router instance: name the `browser_pageload` root from the
11
+ * initial route and open a parameterized `browser_navigation` root per route
12
+ * change. Returns a cleanup that unsubscribes and unregisters. Safe to call
13
+ * before or after tracing is enabled; no-ops when tracing is off. Calling it
14
+ * twice on the same router replaces the first instrumentation rather than
15
+ * stacking a second set of subscriptions.
16
+ */
17
+ function traceTanStackRouter(router) {
18
+ if (typeof router?.subscribe !== "function") return () => {};
19
+ return instrumentOnce(router, (track) => install(router, track));
20
+ }
21
+ function install(router, track) {
22
+ const nav = registerNavigationSource();
23
+ track(() => nav.unregister());
24
+ function hrefOf(loc) {
25
+ return resolveHref(() => loc.publicHref ?? loc.href, loc.pathname);
26
+ }
27
+ function routeNameFor(loc) {
28
+ return routeName(() => {
29
+ const matches = router.matchRoutes(loc.pathname, loc.search, {
30
+ preload: false,
31
+ throwOnError: false
32
+ });
33
+ if (!matches.some((m) => m.routeId !== "__root__")) return;
34
+ const last = matches[matches.length - 1];
35
+ return last?.fullPath || last?.routeId;
36
+ }, loc.pathname, hrefOf(loc));
37
+ }
38
+ try {
39
+ nav.setActiveRouteName(routeNameFor(router.state.location));
40
+ } catch {}
41
+ let inFlight = false;
42
+ let destination = null;
43
+ let staleTimer = null;
44
+ function clearStaleTimer() {
45
+ if (staleTimer !== null) {
46
+ clearTimeout(staleTimer);
47
+ staleTimer = null;
48
+ }
49
+ }
50
+ function settle(location) {
51
+ clearStaleTimer();
52
+ inFlight = false;
53
+ destination = null;
54
+ nav.settleNavigation(routeNameFor(location));
55
+ }
56
+ track(clearStaleTimer);
57
+ track(router.subscribe("onBeforeLoad", insulate((event) => {
58
+ if (event.fromLocation === void 0) return;
59
+ if (event.hrefChanged === false) return;
60
+ if (event.toLocation.state === event.fromLocation.state) return;
61
+ if (!inFlight) {
62
+ inFlight = true;
63
+ nav.startNavigation({
64
+ path: event.toLocation.pathname,
65
+ hold: true
66
+ });
67
+ }
68
+ destination = event.toLocation;
69
+ nav.setActiveRouteName(routeNameFor(event.toLocation));
70
+ clearStaleTimer();
71
+ staleTimer = setTimeout(insulate(() => {
72
+ staleTimer = null;
73
+ if (destination) settle(destination);
74
+ }), STALE_NAVIGATION_TIMEOUT_MS);
75
+ })));
76
+ track(router.subscribe("onResolved", insulate((event) => {
77
+ if (event.fromLocation === void 0) {
78
+ nav.setActiveRouteName(routeNameFor(event.toLocation));
79
+ return;
80
+ }
81
+ if (inFlight) settle(event.toLocation);
82
+ })));
83
+ }
84
+
85
+ //#endregion
86
+ export { STALE_NAVIGATION_TIMEOUT_MS, traceTanStackRouter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/react",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "description": "React client for flareapp.io",
5
5
  "homepage": "https://flareapp.io",
6
6
  "bugs": "https://github.com/spatie/flare-client-js/issues",
@@ -51,22 +51,53 @@
51
51
  "types": "./dist/inject.d.cts",
52
52
  "default": "./dist/inject.cjs"
53
53
  }
54
+ },
55
+ "./tanstack-router": {
56
+ "import": {
57
+ "types": "./dist/tanstack-router.d.mts",
58
+ "default": "./dist/tanstack-router.mjs"
59
+ },
60
+ "require": {
61
+ "types": "./dist/tanstack-router.d.cts",
62
+ "default": "./dist/tanstack-router.cjs"
63
+ }
64
+ },
65
+ "./react-router": {
66
+ "import": {
67
+ "types": "./dist/react-router.d.mts",
68
+ "default": "./dist/react-router.mjs"
69
+ },
70
+ "require": {
71
+ "types": "./dist/react-router.d.cts",
72
+ "default": "./dist/react-router.cjs"
73
+ }
74
+ },
75
+ "./profiler": {
76
+ "import": {
77
+ "types": "./dist/profiler.d.mts",
78
+ "default": "./dist/profiler.mjs"
79
+ },
80
+ "require": {
81
+ "types": "./dist/profiler.d.cts",
82
+ "default": "./dist/profiler.cjs"
83
+ }
54
84
  }
55
85
  },
56
86
  "scripts": {
57
87
  "prepublishOnly": "npm run build",
58
- "build": "tsdown src/index.ts src/inject.ts --format cjs,esm --dts --env.PACKAGE_VERSION=$(node -p \"require('./package.json').version\") --clean",
88
+ "build": "tsdown src/index.ts src/inject.ts src/tanstack-router.ts src/react-router.ts src/profiler.ts --format cjs,esm --dts --env.PACKAGE_VERSION=$(node -p \"require('./package.json').version\") --clean",
59
89
  "test": "vitest run",
60
90
  "typescript": "tsc --noEmit",
61
91
  "verify:inject": "node scripts/verify-inject-no-root.mjs",
62
92
  "release": "release-it"
63
93
  },
64
94
  "dependencies": {
65
- "@flareapp/core": "2.6.0"
95
+ "@flareapp/core": "2.8.0"
66
96
  },
67
97
  "devDependencies": {
68
98
  "@flareapp/electron": "file:../electron",
69
99
  "@flareapp/js": "file:../js",
100
+ "@flareapp/test-helpers": "*",
70
101
  "@testing-library/jest-dom": "^6.9.1",
71
102
  "@testing-library/react": "^16.0.0",
72
103
  "@types/react": "^19.0.0",
@@ -74,13 +105,24 @@
74
105
  "jsdom": "^26.1.0",
75
106
  "react": "^19.0.0",
76
107
  "react-dom": "^19.0.0",
108
+ "react-router": "^7.6.0",
77
109
  "tsdown": "^0.20.3",
78
110
  "typescript": "^5.7.0",
79
111
  "vitest": "^4.0.0"
80
112
  },
81
113
  "peerDependencies": {
82
- "@flareapp/js": "^2.6.0",
83
- "react": "^16.0.0||^17.0.0||^18.0.0||^19.0.0"
114
+ "@flareapp/js": "^2.8.0",
115
+ "@tanstack/react-router": ">=1.64.0 <2",
116
+ "react": "^16.0.0||^17.0.0||^18.0.0||^19.0.0",
117
+ "react-router": ">=7.0.0 <8"
118
+ },
119
+ "peerDependenciesMeta": {
120
+ "@tanstack/react-router": {
121
+ "optional": true
122
+ },
123
+ "react-router": {
124
+ "optional": true
125
+ }
84
126
  },
85
127
  "publishConfig": {
86
128
  "access": "public"