• Will Chen's avatar
    Add MutationObserver retry for component selector initialization (#2408) · 0c122e3b
    Will Chen 提交于
    ## Summary
    
    - Fixes the component selector being permanently disabled when apps have
    delayed first render (e.g., async auth/Supabase initialization)
    - Uses MutationObserver to retry detecting `[data-dyad-id]` elements for
    up to 5 seconds
    - Properly cleans up observer and timeout when elements are found to
    avoid resource leaks
    
    ## Test plan
    
    1. All existing `select component` e2e tests pass (4 tests)
    2. Annotator e2e test passes
    3. For manual testing:
    - Create an app that has delayed initialization (e.g., async auth check
    before rendering)
       - Previously: component selector button would be disabled
       - Now: component selector button should enable once components render
    
    Fixes #2231
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    <!-- devin-review-badge-begin -->
    
    ---
    
    <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2408">
      <picture>
    <source media="(prefers-color-scheme: dark)"
    srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
    <img
    src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
    alt="Open with Devin">
      </picture>
    </a>
    <!-- devin-review-badge-end -->
    
    <!-- CURSOR_SUMMARY -->
    ---
    
    > [!NOTE]
    > **Medium Risk**
    > Adds a long-lived `MutationObserver`/timeout loop to initialization,
    which could affect iframe performance or leave the selector disabled if
    the observer logic misfires, though cleanup and a hard timeout mitigate
    this.
    > 
    > **Overview**
    > Makes the component selector initialization resilient to delayed
    renders by no longer giving up immediately when no `[data-dyad-id]`
    elements exist.
    > 
    > The client now retries by observing DOM/attribute mutations for newly
    tagged elements, posts `dyad-component-selector-initialized` once found,
    and cleans up the observer/timeout; it only logs the “no tagged
    elements” warning after a 60s timeout.
    > 
    > <sup>Written by [Cursor
    Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
    56474bce646c9f41c87c869a4310964efcb62a99. This will update automatically
    on new commits. Configure
    [here](https://cursor.com/dashboard?tab=bugbot).</sup>
    <!-- /CURSOR_SUMMARY -->
    
    <!-- This is an auto-generated description by cubic. -->
    ---
    ## Summary by cubic
    Fixes the component selector staying disabled when apps render late by
    retrying initialization until tagged elements appear. Adds a
    MutationObserver with a 60s timeout and proper cleanup.
    
    - **Bug Fixes**
    - Watch for [data-dyad-id] with a MutationObserver and retry init for up
    to 60s.
    - Disconnect observer and clear timeout once found; warn only if timeout
    expires.
    - Addresses Linear issue #2231 by enabling the selector after delayed
    renders.
    
    <sup>Written for commit 56474bce646c9f41c87c869a4310964efcb62a99.
    Summary will update on new commits.</sup>
    
    <!-- End of auto-generated description by cubic. -->
    
    ---------
    Co-authored-by: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
    0c122e3b
名称
最后提交
最后更新
..
dyad-component-selector-client.js 正在载入提交数据...
dyad-screenshot-client.js 正在载入提交数据...
dyad-shim.js 正在载入提交数据...
dyad-sw-register.js 正在载入提交数据...
dyad-sw.js 正在载入提交数据...
dyad-visual-editor-client.js 正在载入提交数据...
dyad_logs.js 正在载入提交数据...
proxy_server.js 正在载入提交数据...