Skip to content

Fix TikTok browser crashes #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
Merged

Fix TikTok browser crashes #760

merged 2 commits into from
Jun 3, 2025

Conversation

thomshutt
Copy link
Contributor

@thomshutt thomshutt commented Jun 3, 2025

PR Type

Bug fix


Description

  • Guard against undefined navigator in share handler

  • Add navigator check in TikTok browser hook

  • Prevent SSR crashes in analytics tracking

  • Log missing API errors instead of throwing


Changes walkthrough 📝

Relevant files
Error handling
ClipShareContent.tsx
Guard navigator in share handler                                                 

apps/app/components/daydream/Clipping/ClipShareContent.tsx

  • Added undefined navigator guard in share handler
  • Logged error and early returned if API missing
  • +5/-0     
    useIsTikTokBrowser.ts
    Include navigator check in hook                                                   

    apps/app/hooks/useIsTikTokBrowser.ts

  • Included navigator undefined check in useEffect
  • Prevent SSR errors accessing navigator.userAgent
  • +1/-1     
    track.ts
    Guard window/navigator in tracking                                             

    apps/app/lib/track.ts

  • Guarded window and navigator in getBrowserInfo
  • Early return in track if APIs undefined
  • Kept webdriver skip logic intact
  • +8/-5     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    vercel bot commented Jun 3, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    pipelines-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 3, 2025 8:05pm

    Copy link

    github-actions bot commented Jun 3, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Web Share API

    The code checks if navigator is defined but does not verify support for the Web Share API (navigator.share), which may lead to runtime errors in browsers without this feature. Include feature detection or a fallback.

    if (typeof navigator === "undefined") {
      console.error("Navigator API not available");
      return;
    }
    SSR Hydration

    On server-side renders the hook leaves isTikTokBrowser at its initial false, which can cause hydration mismatches and UI flicker. Consider deferring the check or using a hydration-safe pattern.

    if (typeof window !== "undefined" && typeof navigator !== "undefined") {
      const userAgent = window.navigator.userAgent.toLowerCase();
      setIsTikTokBrowser(identifyTikTokInAppBrowser(userAgent));
    }
    Silent Skipped Tracks

    The tracking skip logic returns false under SSR or bot detection without logging, making it hard to debug why events aren’t sent. Consider adding logs when analytics calls are skipped.

    if (typeof window === "undefined" || typeof navigator === "undefined") {
      return false;
    }
    
    if (navigator.webdriver) {
      return false;

    Copy link

    github-actions bot commented Jun 3, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Validate Web Share API support

    Instead of only checking for the existence of the global navigator object, verify
    support for the Web Share API (navigator.share) to avoid runtime errors on browsers
    where navigator exists but the share method does not.

    apps/app/components/daydream/Clipping/ClipShareContent.tsx [47-50]

    -if (typeof navigator === "undefined") {
    -  console.error("Navigator API not available");
    +if (!navigator?.share) {
    +  console.error("Web Share API is not supported in this browser.");
       return;
     }
    Suggestion importance[1-10]: 7

    __

    Why: Checking only for navigator existence misses cases where navigator.share is unsupported; verifying navigator.share prevents runtime errors and improves robustness.

    Medium

    @thomshutt thomshutt requested a review from gioelecerati June 3, 2025 20:05
    @thomshutt thomshutt merged commit 0e25fd8 into main Jun 3, 2025
    6 checks passed
    @thomshutt thomshutt deleted the fix-tiktok branch June 3, 2025 20:06
    thomshutt added a commit that referenced this pull request Jun 3, 2025
    * Fix crashes in TikTok browser
    
    * Formatting
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant