Skip to content

Commit 3d167a7

Browse files
committed
fix: reload dashboard iframe when switching bots
- Add `panel` query parameter to dashboard URL with bot name to force iframe reload, since browsers skip navigation when only query string changes - Pass `botName` prop to StitchDashboardEmbed and use it to generate unique iframe key - Add guard in BotDetail to show loading state when URL name diverges from loaded bot data, preventing stale bot UI from rendering - Update dashboard embed useEffect dependency array to include botName
1 parent 375dc0f commit 3d167a7

6 files changed

Lines changed: 25 additions & 8 deletions

File tree

.textile-monorepo-source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
356a0d47583ff0afdd4747504a82be68193a3271
1+
90f5a945d71d5e9a80914f7681c51fa42621afb4

.textile-stitch-release-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.224
1+
0.1.225

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stitch-bot"
3-
version = "0.1.224"
3+
version = "0.1.225"
44
edition = "2021"
55
description = "Stitch — Textile filler-network operator bot; quotes Swap via RFQ firm quotes and optionally fills resting limit orders."
66
license = "AGPL-3.0-or-later"

web/src/components/StitchDashboardEmbed.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ const INITIAL_IFRAME_HEIGHT_PX = 480
77
const EMBED_HEIGHT_SOURCE = 'textile-stitch-dashboard'
88
const EMBED_HEIGHT_TYPE = 'embed-height'
99

10-
function dashboardUrl(operatorAddress: string): string {
10+
function dashboardUrl(operatorAddress: string, botName?: string): string {
1111
const url = new URL(DATAROOM_STITCH_DASHBOARD)
1212
url.searchParams.set('bot', operatorAddress)
1313
url.searchParams.set('embed', '1')
14+
// Browsers often skip navigating an iframe when only the query changes.
15+
// The panel bot name makes the URL unique per switch so the frame reloads.
16+
if (botName) url.searchParams.set('panel', botName)
1417
return url.toString()
1518
}
1619

@@ -35,10 +38,13 @@ function isEmbedHeightMessage(
3538
*/
3639
export default function StitchDashboardEmbed({
3740
operatorAddress,
41+
botName,
3842
}: {
3943
operatorAddress: string | null | undefined
44+
botName?: string
4045
}) {
4146
const [heightPx, setHeightPx] = useState(INITIAL_IFRAME_HEIGHT_PX)
47+
const frameKey = `${botName ?? ''}:${operatorAddress ?? ''}`
4248

4349
useEffect(() => {
4450
if (!operatorAddress) return
@@ -53,7 +59,7 @@ export default function StitchDashboardEmbed({
5359

5460
window.addEventListener('message', onMessage)
5561
return () => window.removeEventListener('message', onMessage)
56-
}, [operatorAddress])
62+
}, [operatorAddress, botName])
5763

5864
if (!operatorAddress) {
5965
return (
@@ -67,8 +73,9 @@ export default function StitchDashboardEmbed({
6773
return (
6874
<section className="overflow-hidden rounded-xl border border-line-soft bg-[#22242a]">
6975
<iframe
76+
key={frameKey}
7077
title="Stitch dashboard"
71-
src={dashboardUrl(operatorAddress)}
78+
src={dashboardUrl(operatorAddress, botName)}
7279
className="block w-full border-0"
7380
style={{ height: heightPx, overflow: 'hidden' }}
7481
/>

web/src/pages/BotDetail.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ export default function BotDetail() {
161161
}
162162
}
163163

164+
// Never paint the previous bot while the URL name has moved on. The
165+
// dashboard iframe in particular will keep the old document if we do.
166+
if (bot && bot.name !== name) {
167+
if (error) return <ErrorState error={error} onRetry={() => void load()} />
168+
return <Loading what={name} />
169+
}
164170
if (!bot && error) return <ErrorState error={error} onRetry={() => void load()} />
165171
if (!bot) return <Loading what={name} />
166172

@@ -468,7 +474,11 @@ export default function BotDetail() {
468474
)}
469475

470476
{tab === 'dashboard' && (
471-
<StitchDashboardEmbed operatorAddress={bot.config?.operatorAddress} />
477+
<StitchDashboardEmbed
478+
key={name}
479+
botName={name}
480+
operatorAddress={bot.config?.operatorAddress}
481+
/>
472482
)}
473483
</div>
474484
)

0 commit comments

Comments
 (0)