Use the first found port for frontend preview detection (vibe-kanban) (#1046)

* - Updated `frontend/src/hooks/useDevserverUrl.ts:66-84` so new log chunks are scanned in arrival order and the state keeps the very first detected preview URL/port instead of replacing it with later ones.
- Confirmed the hook still resets when the log stream shrinks (new process) so a new attempt can detect a fresh first port.

I wasn’t able to run `pnpm run check` here; feel free to run it locally if you’d like to double-check.

* - Added an early return in `frontend/src/hooks/useDevserverUrl.ts:74-81` so once a preview URL is locked in we simply advance `lastIndexRef` and skip parsing new log entries, avoiding unnecessary work while still resetting correctly if the stream shrinks.
- Extended the effect dependency list to include `urlInfo` so the early-return logic behaves consistently with state updates.

If you want to cover the edge case where the dev server restarts on the same attempt and we intentionally reset the stored URL, we can hook into that next.

* Swapped the index-based `for` with `Array.prototype.some` over a sliced view of the new log entries (`frontend/src/hooks/useDevserverUrl.ts:77-85`). This keeps the “stop at the first hit” behavior but reads a little cleaner and avoids manual index bookkeeping.
This commit is contained in:
Alex Netsch
2025-10-17 14:20:29 +01:00
committed by GitHub
parent 518230f8a0
commit 1090255bd7

View File

@@ -68,18 +68,28 @@ export const useDevserverUrlFromLogs = (
setUrlInfo(undefined); setUrlInfo(undefined);
} }
for (let i = logs.length - 1; i >= lastIndexRef.current; i -= 1) { if (urlInfo) {
const detected = detectDevserverUrl(logs[i].content); lastIndexRef.current = logs.length;
return;
}
let detectedUrl: DevserverUrlInfo | undefined;
const newEntries = logs.slice(lastIndexRef.current);
newEntries.some((entry) => {
const detected = detectDevserverUrl(entry.content);
if (detected) { if (detected) {
setUrlInfo((prev) => detectedUrl = detected;
prev && prev.url === detected.url ? prev : detected return true;
);
break;
} }
return false;
});
if (detectedUrl) {
setUrlInfo((prev) => prev ?? detectedUrl);
} }
lastIndexRef.current = logs.length; lastIndexRef.current = logs.length;
}, [logs]); }, [logs, urlInfo]);
return urlInfo; return urlInfo;
}; };