Skip to content

Commit

Permalink
fix(monitoring): prevent use client directive from getting removed
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPruzan committed Dec 13, 2024
1 parent 14549b2 commit c5ab275
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
1 change: 0 additions & 1 deletion packages/scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"email": "[email protected]",
"url": "https://million.dev"
},
"type": "commonjs",
"exports": {
"./package.json": "./package.json",
"./monitoring": {
Expand Down
2 changes: 1 addition & 1 deletion packages/scan/src/core/monitor/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export let isRSC = !React.useRef;
export let isSSR = typeof window === 'undefined' || isRSC;

export let isTest =
(window &&
(typeof window !== 'undefined' &&
/**
* @see https://docs.cypress.io/faq/questions/using-cypress-faq#Is-there-any-way-to-detect-if-my-app-is-running-under-Cypress
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/scan/src/core/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const Monitoring = ({
// When using Monitoring without framework, we need to compute the route from the path and params
if (!route && path && params) {
Store.monitor.value.route = computeRoute(path, params);
} else {
} else if (typeof window !== 'undefined') {
Store.monitor.value.route =
route ?? path ?? new URL(window.location.toString()).pathname; // this is inaccurate on vanilla react if the path is not provided but used for session route
}
Expand Down
12 changes: 5 additions & 7 deletions packages/scan/src/core/monitor/params/next.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use client';

// adapted from vercel analytics <remember to put link here>
// adapted from: https://github.com/vercel/analytics
import { useParams, usePathname, useSearchParams } from 'next/navigation.js';
// import React from 'react';
import { createElement, Suspense } from 'react';
import { Monitoring as BaseMonitoring, type MonitoringWithoutRouteProps } from '..';
import {
Monitoring as BaseMonitoring,
type MonitoringWithoutRouteProps,
} from '..';
import { computeRoute } from './utils';
// import { computeRoute } from '../utils';
// does this work in pages and app router? Idk
const useRoute = (): {
route: string | null;
path: string;
Expand Down
1 change: 0 additions & 1 deletion packages/scan/src/monitoring/next.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/scan/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export default defineConfig([
format: ['cjs', 'esm'],
target: 'esnext',
platform: 'browser',
treeshake: true,
// FIXME: tree shaking removes use client directive
// Info: vercel analytics does the same thing- https://github.com/vercel/analytics/blob/main/packages/web/tsup.config.js
treeshake: false,
dts: true,
async onSuccess() {
await Promise.all([
Expand Down

0 comments on commit c5ab275

Please sign in to comment.