• Will Chen's avatar
    Fix refresh to preserve current route (#253) (#2336) · eb9f9162
    Will Chen 提交于
    ## Summary
    - When clicking the refresh button in the preview panel, the app now
    preserves the current route instead of defaulting to the root path (/)
    - Store the current URL in a ref when refresh is clicked, then use it as
    the iframe src during reload
    - Added E2E test to verify route preservation on refresh
    
    Fixes #253
    
    ## Test plan
    - E2E test `refresh preserves current route` verifies the fix:
      1. Create an app
    2. Navigate to a different route using JavaScript (simulating
    client-side navigation)
      3. Click refresh
      4. Verify the address bar still shows the navigated route (not /)
    - Existing `refresh app` test continues to pass
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    <!-- devin-review-badge-begin -->
    
    ---
    
    <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2336">
      <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]
    > Ensures the preview iframe keeps the current client-side route on
    refresh and after HMR remounts.
    > 
    > - Track route changes (`pushState`/`replaceState`) and persist per-app
    URL via `previewCurrentUrlAtom`; initialize navigation from preserved
    URL
    > - Use `currentIframeUrlRef` and validated same-origin URL as iframe
    `src` on reload; reset history on app change
    > - Update `PreviewIframe` navigation history, address bar
    (`data-testid="preview-address-bar-path"`), and reload logic; avoid
    unintended src resets on re-render
    > - Add E2E test `refresh preserves current route` with a multi-page
    React Router fixture to verify behavior
    > 
    > <sup>Written by [Cursor
    Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
    d715ec38b8fb94383eafe3a31b901d407468ab4e. 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
    Refresh in the preview panel now preserves the current route instead of
    resetting to /. Routes are also restored after HMR remounts; adds an E2E
    test to confirm this; fixes #253.
    
    - **Bug Fixes**
    - Track route changes (pushState/replaceState) and persist the current
    URL per app via previewCurrentUrlAtom; on reload, validate same-origin
    and use it as the iframe src; reset on app change.
    - Add a data-testid to the address bar and a Playwright test that
    navigates via a react-router link in a multi-page app, refreshes, waits,
    and asserts the route remains.
    
    <sup>Written for commit d715ec38b8fb94383eafe3a31b901d407468ab4e.
    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>
    Co-authored-by: 's avatarclaude[bot] <41898282+claude[bot]@users.noreply.github.com>
    eb9f9162