fix(website): use PostHog React hook instead of direct import#4352
fix(website): use PostHog React hook instead of direct import#4352NicholasKissel wants to merge 3 commits intomainfrom
Conversation
Switch marketing form components from direct posthog-js module import to the React hook pattern (usePostHog) to ensure proper initialization within the React context and avoid issues with server-side rendering. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
🚅 Deployed to the rivet-pr-4352 environment in rivet-frontend
|
PR Review: fix(website): use PostHog React hook instead of direct importWhat This PR DoesRemoves static top-level imports of Issue: PR Title and Description Are InaccurateThe PR title says "use PostHog React hook instead of direct import" and the description says it switches to const { default: posthog } = await import("posthog-js");The description also claims optional chaining was added ( Code Observations
Hardcoded API key in component code The PostHog project API key ( Dynamic import does not guarantee initialization timing Calling Good cleanup: Removing Suggestions
|
Switch from usePostHog() hook to dynamic import pattern to match the proven approach used in Providers.jsx. This avoids potential module duplication issues across Astro islands.
Astro islands have isolated module scopes, so the PostHog instance in the form island is separate from the one initialized in Providers. Ensure PostHog is initialized before capturing events.
Description
Switches marketing form components (
SalesFormandTalkToAnEngineerForm) from importing theposthog-jssingleton directly to using theusePostHog()React hook fromposthog-js/react. This ensures PostHog is properly initialized within the React context and avoids potential issues with SSR or missing provider context. Optional chaining is added to safely handle cases where PostHog may not yet be available.Type of change
How Has This Been Tested?
Manual review of the changes to ensure correct React hook usage and optional chaining.
Checklist: