@veltdev/react 5.0.0-beta.2 → 5.0.0-beta.4

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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- export declare const VELT_SDK_VERSION = "5.0.0-beta.2";
2
+ export declare const VELT_SDK_VERSION = "5.0.0-beta.4";
3
3
  export declare const VELT_SDK_INIT_EVENT = "onVeltInit";
4
4
  export declare const VELT_TAB_ID = "veltTabId";
5
5
  export declare const INTEGRITY_MAP: Record<string, string>;
@@ -1,2 +1,28 @@
1
- declare const loadVelt: (callback: Function, version?: string, staging?: boolean, develop?: boolean, proxyDomain?: string, integrity?: boolean, integrityValue?: string) => void;
1
+ /**
2
+ * Loads the Velt script dynamically and calls the callback when ready.
3
+ * Returns a cleanup function to remove the event listener if component unmounts.
4
+ *
5
+ * ## Issue (Rapid Mount/Unmount with Slow Network)
6
+ *
7
+ * When VeltProvider is rapidly mounted/unmounted (e.g., conditional rendering,
8
+ * React Strict Mode, or route changes) while the Velt script is still loading
9
+ * over a slow network, multiple issues can occur:
10
+ *
11
+ * 1. First component mount creates the script tag and starts loading
12
+ * 2. Component unmounts before script loads (script tag remains in DOM)
13
+ * 3. Second component mount finds existing script tag
14
+ * 4. OLD BEHAVIOR: Immediately triggered callback assuming script was loaded
15
+ * 5. PROBLEM: Script wasn't actually loaded yet (still loading due to network delay)
16
+ * 6. This caused initVelt to run with window.Velt = undefined
17
+ *
18
+ * ## Fix
19
+ *
20
+ * 1. Check if window.Velt exists before triggering callback for existing scripts
21
+ * 2. If script tag exists but window.Velt doesn't, attach a new load event listener
22
+ * 3. Return a cleanup function that removes the event listener when component unmounts
23
+ * 4. This prevents orphaned callbacks from firing on destroyed component instances
24
+ *
25
+ * @returns Cleanup function to remove event listener (call on component unmount)
26
+ */
27
+ declare const loadVelt: (callback: Function, version?: string, staging?: boolean, develop?: boolean, proxyDomain?: string, integrity?: boolean, integrityValue?: string) => (() => void);
2
28
  export default loadVelt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltdev/react",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.4",
4
4
  "description": "Velt is an SDK to add collaborative features to your product within minutes. Example: Comments like Figma, Frame.io, Google docs or sheets, Recording like Loom, Huddles like Slack and much more.",
5
5
  "homepage": "https://velt.dev",
6
6
  "keywords": [