Skip to content

Conversation

@LudwigVonO
Copy link
Collaborator

No description provided.

@vercel
Copy link

vercel bot commented Nov 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
ocobo Ready Ready Preview Nov 12, 2025 4:56pm

- ✅ **Consistency** with existing third-party script patterns
- ✅ **SSR Safety** via `remix-utils/external-scripts`
- ✅ **Performance** - parallel script loading
- ✅ **Maintainability** - centralized script management
- ✅ **Security** - proper environment variable handling
- ✅ **Framework Compliance** - React Router v7 best practices
@wab
Copy link
Collaborator

wab commented Nov 13, 2025

What Was Done

Commit 1: Added AGO chatbot widget as React component
Commit 2: Refactored to follow React Router v7 best practices

The Problem & Solution

Initial Implementation (Component Approach)

  • Created AGO.tsx component with hardcoded configuration
  • Loaded external script inside React component
  • Used direct DOM manipulation with useEffect

Issues Identified

  1. SSR Hydration Mismatch - Server/client rendering inconsistency
  2. Race Conditions - Script configuration set before script loads
  3. Architecture Inconsistency - Different from other third-party scripts
  4. Security Concerns - Hardcoded API keys, no integrity checks

Corrected Implementation (External Scripts Pattern)

  • Follows existing patterns - GTM, Clearbit, HubSpot all use remix-utils/external-scripts
  • SSR-safe - Configuration in <head>, script via ExternalScripts component
  • Environment-driven - API keys from .env variables
  • Performance optimized - Parallel script loading, proper async/defer

Key Learning Points

React Router v7 Best Practices

  1. External scripts belong in handle.scripts(), not React components
  2. Configuration goes in <head> via inline scripts
  3. Environment variables should control third-party integrations

Why This Approach is Better

  • Consistency with existing codebase patterns
  • SSR Safety via framework-managed script loading
  • Performance - scripts load in parallel
  • Security - API keys in environment, not client bundle
  • Maintainability - centralized script management

Files Changed

  • Deleted: app/components/AGO.tsx (wrong pattern)
  • Modified: app/root.tsx (added to scripts array + configuration)
  • Added: Environment variable documentation in CLAUDE.md

Architecture Principle

Third-party widgets should integrate via the framework's script management system, not as React components, unless they provide official React libraries.

@wab wab merged commit f7a317d into main Nov 13, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants