@multiplayer-app/session-recorder-react 1.2.31 → 1.2.33

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.
Files changed (2) hide show
  1. package/README.md +31 -7
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -402,7 +402,7 @@ Notes:
402
402
 
403
403
  - Use `NEXT_PUBLIC_` environment variables for values needed on the client (e.g. `NEXT_PUBLIC_MULTIPLAYER_API_KEY`).
404
404
  - `instrumentation-client.ts` ensures initialization happens before your UI mounts; the provider is still required to wire React context and hooks.
405
- - You can rely on `onRouterTransitionStart` for navigation tracking in Next.js 15.3+, or use the `NavigationTracker` client component as shown below.
405
+ - You can rely on `onRouterTransitionStart` for navigation tracking in Next.js 15.3+.
406
406
 
407
407
  ### Next.js < 15.3
408
408
 
@@ -415,7 +415,6 @@ An official Next.js-specific wrapper is coming soon. Until then, you can use thi
415
415
  import React, { useEffect } from 'react'
416
416
  import dynamic from 'next/dynamic'
417
417
 
418
- // Load provider on the client only
419
418
  const SessionRecorderProvider = dynamic(
420
419
  () => import('@multiplayer-app/session-recorder-react').then((m) => m.SessionRecorderProvider),
421
420
  { ssr: false }
@@ -423,8 +422,9 @@ const SessionRecorderProvider = dynamic(
423
422
 
424
423
  export function Providers({ children }: { children: React.ReactNode }) {
425
424
  useEffect(() => {
425
+ if (typeof window === 'undefined') return
426
426
  let isMounted = true
427
- ;(async () => {
427
+ const initSessionRecorder = async () => {
428
428
  try {
429
429
  const { default: SessionRecorder } = await import('@multiplayer-app/session-recorder-react')
430
430
  if (!isMounted) return
@@ -433,17 +433,20 @@ export function Providers({ children }: { children: React.ReactNode }) {
433
433
  version: '1.0.0',
434
434
  environment: process.env.NEXT_PUBLIC_ENVIRONMENT ?? 'production',
435
435
  apiKey: process.env.NEXT_PUBLIC_MULTIPLAYER_API_KEY!,
436
- showWidget: true
436
+ showWidget: true,
437
+ // If your APIs are on different origins, add them so OTLP headers are propagated
438
+ // format: string | RegExp | Array
439
+ propagateTraceHeaderCorsUrls: [new RegExp('https://api.example.com', 'i')]
437
440
  })
438
441
  } catch (error) {
439
- console.error('[SessionRecorder] init failed:', error)
442
+ console.error('Failed to initialize session recorder', error)
440
443
  }
441
- })()
444
+ }
445
+ initSessionRecorder()
442
446
  return () => {
443
447
  isMounted = false
444
448
  }
445
449
  }, [])
446
-
447
450
  return <SessionRecorderProvider>{children}</SessionRecorderProvider>
448
451
  }
449
452
  ```
@@ -514,6 +517,27 @@ export function NavigationTrackerLegacy() {
514
517
  }
515
518
  ```
516
519
 
520
+ ### Important: Client Components only (Next.js)
521
+
522
+ When using this package in Next.js App Router, ensure any code that uses Session Recorder hooks or APIs runs in a Client Component.
523
+
524
+ - Hooks and selectors such as `useSessionRecorder`, `useSessionRecordingState`, `useIsInitialized`, and `useNavigationRecorder` must be called from files that start with `'use client'`.
525
+ - Any direct usage of `SessionRecorder.*` that touches the browser SDK must also run on the client.
526
+ - Render `SessionRecorderProvider` from a Client Component.
527
+
528
+ #### Example: Reading session state in a Client Component
529
+
530
+ ```tsx
531
+ 'use client'
532
+ import React from 'react'
533
+ import { useSessionRecordingState, SessionState } from '@multiplayer-app/session-recorder-react'
534
+
535
+ export default function SessionStatus() {
536
+ const state = useSessionRecordingState()
537
+ return <span>Session state: {state ?? SessionState.stopped}</span>
538
+ }
539
+ ```
540
+
517
541
  ## TypeScript support
518
542
 
519
543
  All hooks and helpers ship with TypeScript types. To extend the navigation metadata, annotate the `params` or `metadata` properties in your own app code. The package re-exports all relevant browser SDK types for convenience.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplayer-app/session-recorder-react",
3
- "version": "1.2.31",
3
+ "version": "1.2.33",
4
4
  "description": "Multiplayer Fullstack Session Recorder for React (browser wrapper)",
5
5
  "author": {
6
6
  "name": "Multiplayer Software, Inc.",
@@ -35,8 +35,8 @@
35
35
  "@opentelemetry/api": "^1.9.0"
36
36
  },
37
37
  "dependencies": {
38
- "@multiplayer-app/session-recorder-browser": "1.2.31",
39
- "@multiplayer-app/session-recorder-common": "1.2.31"
38
+ "@multiplayer-app/session-recorder-browser": "1.2.33",
39
+ "@multiplayer-app/session-recorder-common": "1.2.33"
40
40
  },
41
41
  "devDependencies": {
42
42
  "eslint": "8.48.0",