clarity-js 0.8.14 → 0.8.16

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/rollup.config.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import alias from "@rollup/plugin-alias";
2
2
  import commonjs from "@rollup/plugin-commonjs";
3
- import resolve from "@rollup/plugin-node-resolve";
3
+ import resolve from "@rollup/plugin-node-resolve";
4
4
  import terser from "@rollup/plugin-terser";
5
5
  import typescript from "@rollup/plugin-typescript";
6
- import pkg from "./package.json" assert { type: 'json' };
6
+ import { readFileSync } from "fs";
7
+
8
+ const pkg = JSON.parse(readFileSync("./package.json", "utf-8"));
7
9
  export default [
8
10
  {
9
11
  input: "src/index.ts",
@@ -28,7 +30,7 @@ export default [
28
30
  if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
29
31
  warn(message);
30
32
  },
31
- plugins: [,
33
+ plugins: [
32
34
  resolve(),
33
35
  typescript(),
34
36
  terser({output: {comments: false}}),
@@ -1,2 +1,2 @@
1
- let version = "0.8.14";
1
+ let version = "0.8.16";
2
2
  export default version;
@@ -134,6 +134,10 @@ async function upload(final: boolean = false): Promise<void> {
134
134
  // could inject function arguments for internal tracking (likely stack traces for script errors).
135
135
  // For these edge cases, we want to ensure that an injected object (e.g. {"key": "value"}) isn't mistaken to be true.
136
136
  let last = final === true;
137
+
138
+ // In some cases envelope has null data because it's part of the shutdown process while there's one upload call queued which might introduce runtime error
139
+ if(!envelope.data) return;
140
+
137
141
  let e = JSON.stringify(envelope.envelope(last));
138
142
  let a = `[${analysis.join()}]`;
139
143
 
@@ -33,6 +33,10 @@ function recompute(event: UIEvent = null): void {
33
33
  let de = document.documentElement;
34
34
  let element = event ? target(event) : de;
35
35
 
36
+ // In some edge cases, it's possible for target to be null.
37
+ // In those cases, we cannot proceed with scroll event instrumentation.
38
+ if (!element) { return; }
39
+
36
40
  // If the target is a Document node, then identify corresponding documentElement and window for this document
37
41
  if (element && element.nodeType === Node.DOCUMENT_NODE) {
38
42
  let frame = iframe(element);
@@ -1,4 +1,4 @@
1
- import { Event, Metric } from "@clarity-types/data";
1
+ import { Event } from "@clarity-types/data";
2
2
  import { StyleSheetOperation, StyleSheetState } from "@clarity-types/layout";
3
3
  import { time } from "@src/core/time";
4
4
  import { shortid } from "@src/data/metadata";
@@ -99,10 +99,17 @@ export function stop(): void {
99
99
  if (observer) { observer.disconnect(); }
100
100
  observer = null;
101
101
  interaction.resetInteractions();
102
+ anchorCache = null;
102
103
  }
103
104
 
105
+ // Cached anchor element for optimal performance & memory management
106
+ let anchorCache: HTMLAnchorElement | null = null;
107
+
104
108
  function host(url: string): string {
105
- let a = document.createElement("a");
106
- a.href = url;
107
- return a.host;
109
+ if (!anchorCache) {
110
+ anchorCache = document.createElement("a");
111
+ }
112
+
113
+ anchorCache.href = url;
114
+ return anchorCache.host;
108
115
  }