@m13v/seo-components 0.16.1 → 0.16.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m13v/seo-components",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "scripts": {
5
5
  "build:css": "tailwind -i src/_build.css -o dist/styles.css --minify",
6
6
  "bump:consumers": "bash scripts/bump-consumers.sh",
@@ -75,41 +75,44 @@ export function FullSiteAnalytics({
75
75
  return;
76
76
  }
77
77
  let cancelled = false;
78
- // Defer init to idle to keep it off the critical path.
79
- const ric: (
80
- cb: IdleRequestCallback,
81
- opts?: IdleRequestOptions,
82
- ) => number =
83
- typeof window !== "undefined" && window.requestIdleCallback
84
- ? window.requestIdleCallback.bind(window)
85
- : (cb) => setTimeout(cb as unknown as () => void, 1) as unknown as number;
86
- const cic: (id: number) => void =
87
- typeof window !== "undefined" && window.cancelIdleCallback
88
- ? window.cancelIdleCallback.bind(window)
89
- : (id) => clearTimeout(id);
90
- const id = ric(
91
- () => {
92
- import("posthog-js").then((mod) => {
93
- if (cancelled) return;
94
- const lib = mod.default;
95
- lib.init(posthogKey, {
96
- api_host: posthogHost,
97
- person_profiles: personProfiles,
98
- capture_pageview: capturePageview,
99
- capture_pageleave: capturePageleave,
100
- });
101
- // Legacy: some helpers still read window.posthog. Setting this
102
- // is what 3 of 4 consumer sites forgot, which silently broke
103
- // newsletter_subscribed and schedule_click events.
104
- (window as unknown as { posthog: typeof lib }).posthog = lib;
105
- setPosthog(lib as unknown as PostHogLike);
78
+ let idleId: number | undefined;
79
+ let timeoutId: ReturnType<typeof setTimeout> | undefined;
80
+
81
+ const run = () => {
82
+ import("posthog-js").then((mod) => {
83
+ if (cancelled) return;
84
+ const lib = mod.default;
85
+ lib.init(posthogKey, {
86
+ api_host: posthogHost,
87
+ person_profiles: personProfiles,
88
+ capture_pageview: capturePageview,
89
+ capture_pageleave: capturePageleave,
106
90
  });
107
- },
108
- { timeout: 3000 },
109
- );
91
+ // Legacy: some helpers still read window.posthog. Setting this
92
+ // is what 3 of 4 consumer sites forgot, which silently broke
93
+ // newsletter_subscribed and schedule_click events.
94
+ (window as unknown as { posthog: typeof lib }).posthog = lib;
95
+ setPosthog(lib as unknown as PostHogLike);
96
+ });
97
+ };
98
+
99
+ // Defer init to idle to keep it off the critical path.
100
+ if (typeof window !== "undefined" && window.requestIdleCallback) {
101
+ idleId = window.requestIdleCallback(run, { timeout: 3000 });
102
+ } else {
103
+ timeoutId = setTimeout(run, 1);
104
+ }
105
+
110
106
  return () => {
111
107
  cancelled = true;
112
- cic(id);
108
+ if (
109
+ idleId !== undefined &&
110
+ typeof window !== "undefined" &&
111
+ window.cancelIdleCallback
112
+ ) {
113
+ window.cancelIdleCallback(idleId);
114
+ }
115
+ if (timeoutId !== undefined) clearTimeout(timeoutId);
113
116
  };
114
117
  }, [
115
118
  posthogKey,