peachsim 0.1.761 → 0.1.763

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +5 -0
  2. package/cli/bridge-flow-runner.ts +3 -4
  3. package/cli/commands/inspect/settling.ts +193 -162
  4. package/dist-lib/agent-daemon-client.cjs +1 -1
  5. package/dist-lib/agent-events.cjs +1 -1
  6. package/dist-lib/agent-identity.cjs +1 -1
  7. package/dist-lib/agent-sessions.cjs +1 -1
  8. package/dist-lib/attached-projects.cjs +1 -1
  9. package/dist-lib/auth/shared-session.cjs +1 -1
  10. package/dist-lib/backend-origin.cjs +1 -1
  11. package/dist-lib/beta.cjs +1 -1
  12. package/dist-lib/beta.mjs +1 -1
  13. package/dist-lib/bridge-constants.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.mjs +1 -1
  16. package/dist-lib/bridge-contract.cjs +1 -1
  17. package/dist-lib/bridge-contract.mjs +1 -1
  18. package/dist-lib/capture-contract.cjs +1 -1
  19. package/dist-lib/capture-contract.mjs +1 -1
  20. package/dist-lib/cli-constants.cjs +1 -1
  21. package/dist-lib/cloud-contract.cjs +1 -1
  22. package/dist-lib/cloud-contract.mjs +1 -1
  23. package/dist-lib/cloud-test-args.cjs +1 -1
  24. package/dist-lib/cloud-test-args.mjs +1 -1
  25. package/dist-lib/cloud.cjs +1 -1
  26. package/dist-lib/cloud.mjs +1 -1
  27. package/dist-lib/config.cjs +1 -1
  28. package/dist-lib/detox/index.cjs +1 -1
  29. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  30. package/dist-lib/home-paths.cjs +1 -1
  31. package/dist-lib/host/bridge-host.cjs +44 -37
  32. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  33. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  34. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  35. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  36. package/dist-lib/host/websocket-proxy.cjs +1 -1
  37. package/dist-lib/index.cjs +191 -159
  38. package/dist-lib/jump-to-source-babel.cjs +1 -1
  39. package/dist-lib/jump-to-source-native.cjs +1 -1
  40. package/dist-lib/kotlin-host.cjs +1 -1
  41. package/dist-lib/menu.cjs +1 -1
  42. package/dist-lib/menu.mjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  45. package/dist-lib/metro-production-bundle.cjs +1 -1
  46. package/dist-lib/metro-production-bundle.mjs +1 -1
  47. package/dist-lib/metro.cjs +1 -1
  48. package/dist-lib/native-app-identity.cjs +1 -1
  49. package/dist-lib/native-app-identity.mjs +1 -1
  50. package/dist-lib/native-firebase-metadata.cjs +1 -1
  51. package/dist-lib/native-firebase-metadata.mjs +1 -1
  52. package/dist-lib/plist.cjs +1 -1
  53. package/dist-lib/plist.mjs +1 -1
  54. package/dist-lib/profiles.cjs +1 -1
  55. package/dist-lib/public-brand.cjs +1 -1
  56. package/dist-lib/react-native-host-modules.cjs +1 -1
  57. package/dist-lib/react-native-host-modules.mjs +1 -1
  58. package/dist-lib/render-mode.cjs +1 -1
  59. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  60. package/dist-lib/sdk.cjs +191 -159
  61. package/dist-lib/sdk.mjs +191 -159
  62. package/dist-lib/skills.cjs +240 -202
  63. package/dist-lib/swift-compile.cjs +1 -1
  64. package/dist-lib/swift-compile.mjs +1 -1
  65. package/dist-lib/swift-package.cjs +1 -1
  66. package/dist-lib/swift-package.mjs +1 -1
  67. package/dist-lib/swift-submit.cjs +1 -1
  68. package/dist-lib/swift-submit.mjs +1 -1
  69. package/dist-lib/swift-toolchain.cjs +1 -1
  70. package/dist-lib/swift.cjs +1 -1
  71. package/dist-lib/vite-swift.cjs +1 -1
  72. package/dist-lib/vite.cjs +1 -1
  73. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/native-firebase-metadata.ts
4
4
  var PREFIX = "globalThis.__peachNativeFirebaseConfig=";
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/plist.ts
4
4
  import plist from "plist";
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/react-native-host-modules.ts
4
4
  var REACT_NATIVE_PASSTHROUGH_SPECIFIERS = [
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
package/dist-lib/sdk.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.761 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.763 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1530,179 +1530,211 @@ async function waitForSootsimIdle({
1530
1530
  const start = Date.now()
1531
1531
  const deadline = start + ${Math.max(0, Math.round(maxMs))}
1532
1532
  const pollMs = ${Math.max(1, Math.round(pollMs))}
1533
- const requiredStillMs = ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
1534
- const minimumStablePolls = ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
1535
1533
  const strict = ${strict ? "true" : "false"}
1536
1534
  const paintStill = ${paintStill ? "true" : "false"}
1535
+ const requiredStillMs = paintStill ? 0 : ${Math.max(1, Math.round(stablePolls)) * Math.max(1, Math.round(pollMs))}
1536
+ const minimumStablePolls = paintStill ? 1 : ${Math.min(2, Math.max(1, Math.round(stablePolls)))}
1537
1537
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
1538
-
1539
- // route-aware settle: a tap that pushes/pops a screen is async \u2014 the
1540
- // old screen still renders for a moment, then the new one mounts and
1541
- // its content loads. a pure layout-hash check reports "idle" on the
1542
- // outgoing screen or on the incoming skeleton, so a driver re-taps
1543
- // and stacks duplicate navigations. drain any in-flight screen
1544
- // transition FIRST, bounded by the overall budget. when no
1545
- // transition is happening this returns in ~80ms (startWindowMs), so
1546
- // a plain button tap barely pays for it.
1538
+ const composite = paintStill ? window.SootSim?.bridges?.liveComposite : null
1539
+ if (paintStill && !composite) {
1540
+ return { settled: false, elapsed: Date.now() - start, blockedBy: 'screen pixels unavailable' }
1541
+ }
1542
+ // subscribe to presented frames; authoritative screenshots force a
1543
+ // worker render, which changes the very counter we used to inspect.
1544
+ const unsubscribe = composite?.subscribe(() => {})
1545
+ let pixelFrameToken = -1
1546
+ let screenPixels = null
1547
1547
  try {
1548
- const wfst = window.__sootsimTest?.waitForScreenTransitions
1549
- if (typeof wfst === 'function') {
1550
- const remaining = deadline - Date.now()
1551
- if (remaining > 120) {
1552
- await wfst({
1553
- timeoutMs: Math.min(remaining - 80, 4000),
1554
- settleMs: 64,
1555
- startWindowMs: 80,
1556
- })
1548
+
1549
+ // route-aware settle: a tap that pushes/pops a screen is async \u2014 the
1550
+ // old screen still renders for a moment, then the new one mounts and
1551
+ // its content loads. a pure layout-hash check reports "idle" on the
1552
+ // outgoing screen or on the incoming skeleton, so a driver re-taps
1553
+ // and stacks duplicate navigations. drain any in-flight screen
1554
+ // transition FIRST, bounded by the overall budget. when no
1555
+ // transition is happening this returns in ~80ms (startWindowMs), so
1556
+ // a plain button tap barely pays for it.
1557
+ try {
1558
+ const wfst = window.__sootsimTest?.waitForScreenTransitions
1559
+ if (typeof wfst === 'function') {
1560
+ const remaining = deadline - Date.now()
1561
+ if (remaining > 120) {
1562
+ await wfst({
1563
+ timeoutMs: Math.min(remaining - 80, 4000),
1564
+ settleMs: 64,
1565
+ startWindowMs: 80,
1566
+ })
1567
+ }
1557
1568
  }
1558
- }
1559
- } catch {}
1569
+ } catch {}
1560
1570
 
1561
- const readSnapshot = async () => {
1562
- let animating = false
1563
- let layoutDirty = false
1564
- let pendingFetches = 0
1565
- let requestTotal = 0
1566
- let requestInFlight = 0
1567
- let renderStatsAvailable = false
1568
- let frameCount = -1
1569
- let shellAnimating = false
1570
- // strict also waits out shell motion: a system alert, sheet or menu
1571
- // animates in the shell worker while the app's own stats read still,
1572
- // so its presentation is complete only once the shell's list empties.
1573
- if (strict) {
1571
+ const readSnapshot = async () => {
1572
+ let animating = false
1573
+ let layoutDirty = false
1574
+ let pendingFetches = 0
1575
+ let requestTotal = 0
1576
+ let requestInFlight = 0
1577
+ let renderStatsAvailable = false
1578
+ let shellAnimating = false
1579
+ // strict also waits out shell motion: a system alert, sheet or menu
1580
+ // animates in the shell worker while the app's own stats read still,
1581
+ // so its presentation is complete only once the shell's list empties.
1582
+ if (strict) {
1583
+ try {
1584
+ const motion = await window.__sootsimTest?.listAnimations?.()
1585
+ shellAnimating = Array.isArray(motion) && motion.some((anim) => anim.realm === 'shell')
1586
+ } catch {}
1587
+ }
1574
1588
  try {
1575
- const motion = await window.__sootsimTest?.listAnimations?.()
1576
- shellAnimating = Array.isArray(motion) && motion.some((anim) => anim.realm === 'shell')
1589
+ const stats = await window.__sootsimRenderHost?.queryStats?.()
1590
+ if (stats) {
1591
+ renderStatsAvailable = true
1592
+ animating =
1593
+ stats.hasActiveAnims === true ||
1594
+ stats.hasActiveNativeAnimations === true ||
1595
+ stats.hasPendingAnimationFrames === true
1596
+ layoutDirty =
1597
+ stats.layoutDirty === true && stats.renderRequested === true
1598
+ // a freshly-pushed screen showing a skeleton is layout-stable
1599
+ // but not actually settled \u2014 its data/images are still in
1600
+ // flight. treat bounded image-loader fetches as not-idle so
1601
+ // settle waits for real content, capped by the budget.
1602
+ const pf = stats.memory && stats.memory.imageLoader
1603
+ ? stats.memory.imageLoader.pendingFetches
1604
+ : 0
1605
+ pendingFetches = typeof pf === 'number' ? pf : 0
1606
+ }
1577
1607
  } catch {}
1578
- }
1579
- try {
1580
- const stats = await window.__sootsimRenderHost?.queryStats?.()
1581
- if (stats) {
1582
- renderStatsAvailable = true
1583
- frameCount = typeof stats.frameCount === 'number' ? stats.frameCount : -1
1584
- animating =
1585
- stats.hasActiveAnims === true ||
1586
- stats.hasActiveNativeAnimations === true ||
1587
- stats.hasPendingAnimationFrames === true
1588
- layoutDirty =
1589
- stats.layoutDirty === true && stats.renderRequested === true
1590
- // a freshly-pushed screen showing a skeleton is layout-stable
1591
- // but not actually settled \u2014 its data/images are still in
1592
- // flight. treat bounded image-loader fetches as not-idle so
1593
- // settle waits for real content, capped by the budget.
1594
- const pf = stats.memory && stats.memory.imageLoader
1595
- ? stats.memory.imageLoader.pendingFetches
1596
- : 0
1597
- pendingFetches = typeof pf === 'number' ? pf : 0
1608
+ try {
1609
+ const counts = await window.__sootsimTest?.getRequestCounts?.()
1610
+ requestTotal = typeof counts?.total === 'number' ? counts.total : 0
1611
+ requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight : 0
1612
+ } catch {}
1613
+ const root = window.__sootsimRoot
1614
+ const nodes = []
1615
+ if (root) {
1616
+ const walk = (n) => {
1617
+ if (n.layout && n.layout.width > 0) {
1618
+ nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
1619
+ }
1620
+ for (const c of n.children || []) walk(c)
1621
+ }
1622
+ walk(root)
1598
1623
  }
1599
- } catch {}
1600
- try {
1601
- const counts = await window.__sootsimTest?.getRequestCounts?.()
1602
- requestTotal = typeof counts?.total === 'number' ? counts.total : 0
1603
- requestInFlight = typeof counts?.inFlight === 'number' ? counts.inFlight : 0
1604
- } catch {}
1605
- const root = window.__sootsimRoot
1606
- const nodes = []
1607
- if (root) {
1608
- const walk = (n) => {
1609
- if (n.layout && n.layout.width > 0) {
1610
- nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
1624
+ if (paintStill) {
1625
+ const canvas = composite.getCanvas()
1626
+ const token = composite.getFrameToken()
1627
+ if (!canvas || canvas.width <= 1 || canvas.height <= 1) {
1628
+ screenPixels = null
1629
+ } else if (token !== pixelFrameToken || canvas.width !== screenPixels?.width || canvas.height !== screenPixels?.height) {
1630
+ const context = canvas.getContext('2d')
1631
+ const image = context?.getImageData(0, 0, canvas.width, canvas.height)
1632
+ screenPixels = image ? { width: image.width, height: image.height, data: new Uint32Array(image.data.buffer) } : null
1633
+ pixelFrameToken = token
1611
1634
  }
1612
- for (const c of n.children || []) walk(c)
1613
1635
  }
1614
- walk(root)
1636
+ return { layout: nodes.join(';'), screenPixels, animating, shellAnimating, layoutDirty, pendingFetches, renderStatsAvailable, requestTotal, requestInFlight }
1615
1637
  }
1616
- return { layout: nodes.join(';'), frameCount, animating, shellAnimating, layoutDirty, pendingFetches, renderStatsAvailable, requestTotal, requestInFlight }
1617
- }
1618
1638
 
1619
- // how long generic background network is allowed to keep us waiting AFTER
1620
- // the screen is otherwise visually settled. apps with continuous traffic
1621
- // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
1622
- // requestInFlight===0 / a stable requestTotal, so requiring full network
1623
- // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
1624
- // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
1625
- // layout-stability + the image-loader already prove visible content
1626
- // loaded (a data load changes layout; an image load shows in the loader),
1627
- // so the generic request counters are a courtesy, not a gate: honor them
1628
- // only within this grace once the screen is visually still.
1629
- const networkQuietGraceMs = 1200
1630
- let lastLayout = ''
1631
- let lastFrameCount = -2
1632
- let paintedPolls = 0
1633
- let lastRequestTotal = -1
1634
- let stable = 0
1635
- let visuallyStillSince = 0
1636
- // counts across the whole budget: a flag that is true on every poll is a
1637
- // different bug from one that is true intermittently, and the two need
1638
- // opposite fixes (engine vs budget).
1639
- let polls = 0
1640
- let dirtyPolls = 0
1641
- let animatingPolls = 0
1642
- let layoutChangedPolls = 0
1643
- while (Date.now() < deadline) {
1644
- const snapshot = await readSnapshot()
1645
- polls++
1646
- if (snapshot.layoutDirty) dirtyPolls++
1647
- if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
1648
- if (polls > 1 && snapshot.layout !== lastLayout) layoutChangedPolls++
1649
- const painted = paintStill && snapshot.frameCount !== lastFrameCount
1650
- if (polls > 1 && painted) paintedPolls++
1651
- const strictOk =
1652
- !strict ||
1653
- (snapshot.renderStatsAvailable &&
1654
- !snapshot.animating &&
1655
- !snapshot.shellAnimating &&
1656
- !snapshot.layoutDirty)
1657
- // visually settled: no animations, no image content loading, layout
1658
- // unchanged since the last poll.
1659
- const visuallyStill =
1660
- strictOk &&
1661
- !painted &&
1662
- snapshot.pendingFetches === 0 &&
1663
- snapshot.layout === lastLayout
1664
- // generic network quiet: nothing in flight and no new requests issued.
1665
- const networkQuiet =
1666
- snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
1667
- if (visuallyStill) {
1668
- stable++
1669
- if (visuallyStillSince === 0) visuallyStillSince = Date.now()
1670
- // settle once the screen has held still long enough AND either the
1671
- // network is genuinely quiet OR it has refused to quiet within the
1672
- // grace (continuous background traffic must not block forever).
1673
- if (
1674
- stable >= minimumStablePolls &&
1675
- Date.now() - visuallyStillSince >= requiredStillMs &&
1676
- (networkQuiet || Date.now() - visuallyStillSince >= networkQuietGraceMs)
1677
- ) {
1678
- return { settled: true, elapsed: Date.now() - start, blockedBy: '' }
1639
+ // how long generic background network is allowed to keep us waiting AFTER
1640
+ // the screen is otherwise visually settled. apps with continuous traffic
1641
+ // (polling, realtime sockets, a tap that fires 20-50 fetches) never reach
1642
+ // requestInFlight===0 / a stable requestTotal, so requiring full network
1643
+ // quiet burns the ENTIRE budget on every command \u2014 the leading idle that
1644
+ // failed PR-preview recordings for network-heavy apps (3pc fight-pulse).
1645
+ // layout-stability + the image-loader already prove visible content
1646
+ // loaded (a data load changes layout; an image load shows in the loader),
1647
+ // so the generic request counters are a courtesy, not a gate: honor them
1648
+ // only within this grace once the screen is visually still.
1649
+ const networkQuietGraceMs = 1200
1650
+ let lastLayout = ''
1651
+ let lastScreenPixels = null
1652
+ let screenChangedPolls = 0
1653
+ let lastRequestTotal = -1
1654
+ let stable = 0
1655
+ let visuallyStillSince = 0
1656
+ // counts across the whole budget: a flag that is true on every poll is a
1657
+ // different bug from one that is true intermittently, and the two need
1658
+ // opposite fixes (engine vs budget).
1659
+ let polls = 0
1660
+ let dirtyPolls = 0
1661
+ let animatingPolls = 0
1662
+ let layoutChangedPolls = 0
1663
+ const screenUnchanged = (pixels) => {
1664
+ if (!pixels || !lastScreenPixels || pixels.width !== lastScreenPixels.width || pixels.height !== lastScreenPixels.height) return false
1665
+ if (pixels === lastScreenPixels) return true
1666
+ for (let i = 0; i < pixels.data.length; i++) {
1667
+ if (pixels.data[i] !== lastScreenPixels.data[i]) return false
1679
1668
  }
1680
- } else {
1681
- stable = 0
1682
- visuallyStillSince = 0
1669
+ return true
1683
1670
  }
1684
- lastLayout = snapshot.layout
1685
- lastFrameCount = snapshot.frameCount
1686
- lastRequestTotal = snapshot.requestTotal
1687
- await sleep(pollMs)
1688
- }
1689
- const last = await readSnapshot()
1690
- const blockers = []
1691
- if (strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
1692
- if (last.animating) blockers.push('animations still running')
1693
- if (last.shellAnimating) blockers.push('shell animations still running')
1694
- if (last.layoutDirty) blockers.push('layout still dirty')
1695
- if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
1696
- if (last.layout !== lastLayout) blockers.push('layout still changing')
1697
- if (paintStill && last.frameCount !== lastFrameCount) blockers.push('still painting')
1698
- if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
1699
- return {
1700
- settled: false,
1701
- elapsed: Date.now() - start,
1702
- blockedBy:
1703
- (blockers.length ? blockers.join(', ') : 'unknown') +
1704
- ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
1705
- 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, painted ' + paintedPolls + 'x)',
1671
+ while (Date.now() < deadline) {
1672
+ const snapshot = await readSnapshot()
1673
+ polls++
1674
+ if (snapshot.layoutDirty) dirtyPolls++
1675
+ if (snapshot.animating || snapshot.shellAnimating) animatingPolls++
1676
+ if (polls > 1 && snapshot.layout !== lastLayout) layoutChangedPolls++
1677
+ const screenChanged = paintStill && !screenUnchanged(snapshot.screenPixels)
1678
+ if (polls > 1 && screenChanged) screenChangedPolls++
1679
+ const strictOk =
1680
+ !strict ||
1681
+ (snapshot.renderStatsAvailable &&
1682
+ !snapshot.animating &&
1683
+ !snapshot.shellAnimating &&
1684
+ !snapshot.layoutDirty)
1685
+ // visually settled: no animations, no image content loading, layout
1686
+ // unchanged since the last poll.
1687
+ const visuallyStill =
1688
+ strictOk &&
1689
+ !screenChanged &&
1690
+ snapshot.pendingFetches === 0 &&
1691
+ snapshot.layout === lastLayout
1692
+ // generic network quiet: nothing in flight and no new requests issued.
1693
+ const networkQuiet =
1694
+ snapshot.requestInFlight === 0 && snapshot.requestTotal === lastRequestTotal
1695
+ if (visuallyStill) {
1696
+ stable++
1697
+ if (visuallyStillSince === 0) visuallyStillSince = Date.now()
1698
+ // settle once the screen has held still long enough AND either the
1699
+ // network is genuinely quiet OR it has refused to quiet within the
1700
+ // grace (continuous background traffic must not block forever).
1701
+ if (
1702
+ stable >= minimumStablePolls &&
1703
+ Date.now() - visuallyStillSince >= requiredStillMs &&
1704
+ (networkQuiet || Date.now() - visuallyStillSince >= networkQuietGraceMs)
1705
+ ) {
1706
+ return { settled: true, elapsed: Date.now() - start, blockedBy: '' }
1707
+ }
1708
+ } else {
1709
+ stable = 0
1710
+ visuallyStillSince = 0
1711
+ }
1712
+ lastLayout = snapshot.layout
1713
+ lastScreenPixels = snapshot.screenPixels
1714
+ lastRequestTotal = snapshot.requestTotal
1715
+ await sleep(pollMs)
1716
+ }
1717
+ const last = await readSnapshot()
1718
+ const blockers = []
1719
+ if (strict && !last.renderStatsAvailable) blockers.push('render stats unavailable')
1720
+ if (last.animating) blockers.push('animations still running')
1721
+ if (last.shellAnimating) blockers.push('shell animations still running')
1722
+ if (last.layoutDirty) blockers.push('layout still dirty')
1723
+ if (last.pendingFetches > 0) blockers.push(last.pendingFetches + ' image fetches pending')
1724
+ if (last.layout !== lastLayout) blockers.push('layout still changing')
1725
+ if (paintStill && !last.screenPixels) blockers.push('screen pixels unavailable')
1726
+ else if (paintStill && !screenUnchanged(last.screenPixels)) blockers.push('screen pixels still changing')
1727
+ if (last.requestInFlight > 0) blockers.push(last.requestInFlight + ' requests in flight')
1728
+ return {
1729
+ settled: false,
1730
+ elapsed: Date.now() - start,
1731
+ blockedBy:
1732
+ (blockers.length ? blockers.join(', ') : 'unknown') +
1733
+ ' over ' + polls + ' polls (layout changed ' + layoutChangedPolls +
1734
+ 'x, layoutDirty ' + dirtyPolls + 'x, animating ' + animatingPolls + 'x, screen changed ' + screenChangedPolls + 'x)',
1735
+ }
1736
+ } finally {
1737
+ unsubscribe?.()
1706
1738
  }
1707
1739
  })()`
1708
1740
  },