• 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
名称
最后提交
最后更新
.claude 正在载入提交数据...
.cursor/rules 正在载入提交数据...
.devcontainer 正在载入提交数据...
.github 正在载入提交数据...
.husky 正在载入提交数据...
assets 正在载入提交数据...
docs 正在载入提交数据...
drizzle 正在载入提交数据...
e2e-tests 正在载入提交数据...
makers 正在载入提交数据...
packages/@dyad-sh 正在载入提交数据...
scaffold 正在载入提交数据...
scripts 正在载入提交数据...
shared 正在载入提交数据...
src 正在载入提交数据...
testing 正在载入提交数据...
tools 正在载入提交数据...
worker 正在载入提交数据...
workers/tsc 正在载入提交数据...
.cursorignore 正在载入提交数据...
.env.example 正在载入提交数据...
.eslintrc.json 正在载入提交数据...
.gitattributes 正在载入提交数据...
.gitignore 正在载入提交数据...
.oxfmtrc.json 正在载入提交数据...
.oxlintrc.json 正在载入提交数据...
.prettierignore 正在载入提交数据...
.prettierrc 正在载入提交数据...
AGENTS.md 正在载入提交数据...
CLA.md 正在载入提交数据...
CLAUDE.md 正在载入提交数据...
CONTRIBUTING.md 正在载入提交数据...
LICENSE 正在载入提交数据...
README.md 正在载入提交数据...
SECURITY.md 正在载入提交数据...
biome.json 正在载入提交数据...
components.json 正在载入提交数据...
drizzle.config.ts 正在载入提交数据...
forge.config.ts 正在载入提交数据...
forge.env.d.ts 正在载入提交数据...
index.html 正在载入提交数据...
lint-staged.config.js 正在载入提交数据...
merge.config.ts 正在载入提交数据...
package-lock.json 正在载入提交数据...
package.json 正在载入提交数据...
playwright.config.ts 正在载入提交数据...
tsconfig.app.json 正在载入提交数据...
tsconfig.json 正在载入提交数据...
tsconfig.node.json 正在载入提交数据...
vite.main.config.mts 正在载入提交数据...
vite.preload.config.mts 正在载入提交数据...
vite.renderer.config.mts 正在载入提交数据...
vite.worker.config.mts 正在载入提交数据...
vitest.config.ts 正在载入提交数据...
windowsSign.ts 正在载入提交数据...