Skip to content

Commit 0d6853e

Browse files
Fix for mixed mode component rendering (#22)
1 parent 6b980b4 commit 0d6853e

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/components/VisualSiftQueryEditor.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,27 @@ export const VisualSiftQueryEditor = (props: Props) => {
1717
const [loading, setLoading] = useState(true);
1818
const [queryMode, setQueryMode] = useState<QueryType>(QueryTypes.CHANNEL);
1919
const [lastQuery, setLastQuery] = useState<string>('');
20+
const [initialRender, setInitialRender] = useState(true);
2021

2122
const queryRef = useRef(query);
2223
useEffect(() => {
2324
queryRef.current = query;
2425
}, [query]);
2526

26-
// Migrate legacy query if necessary
27+
// After initial render, we will perform migrations. This ensures the component renders in Mixed Mode
2728
useEffect(() => {
29+
const timer = setTimeout(() => {
30+
setInitialRender(false); // Trigger migration after initial render
31+
}, 0);
32+
33+
return () => clearTimeout(timer);
34+
}, []); // Only run once on mount
35+
36+
useEffect(() => {
37+
if (!loading || initialRender) {
38+
return;
39+
} // Only migrate once and after initial render
40+
2841
async function migrateQuery() {
2942
// Only migrate if needed or if query has changed
3043
const migratedQuery = await datasource.migrateQuery(query);
@@ -42,7 +55,7 @@ export const VisualSiftQueryEditor = (props: Props) => {
4255
setLoading(false);
4356
}
4457
void migrateQuery();
45-
}, [query, datasource, onChange]); // Re-run when query changes
58+
}, [query, datasource, onChange, initialRender, loading]); // Re-run when query changes
4659

4760
const onUpdateQuery = useCallback(
4861
(query: SiftQuery) => {
@@ -73,7 +86,7 @@ export const VisualSiftQueryEditor = (props: Props) => {
7386
);
7487

7588
if (loading) {
76-
return <div data-testid="loading-migration-placeholder" />;
89+
return <div data-testid="loading-migration-placeholder">Migrating query versions...</div>;
7790
}
7891

7992
return (

0 commit comments

Comments
 (0)