Skip to content

Commit 71bd4c7

Browse files
Copilothotlong
andcommitted
Add cleanup function to prevent race conditions in PluginLoader
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 476e140 commit 71bd4c7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

apps/site/app/components/PluginLoader.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ export function PluginLoader({ plugins, children }: PluginLoaderProps) {
3939
const [loaded, setLoaded] = useState(false);
4040

4141
useEffect(() => {
42+
let cancelled = false;
43+
4244
const loadPlugins = async () => {
4345
// On server side, skip actual imports but mark as loaded to avoid hydration mismatch
4446
if (typeof window === 'undefined') {
45-
setLoaded(true);
47+
if (!cancelled) {
48+
setLoaded(true);
49+
}
4650
return;
4751
}
4852

@@ -85,14 +89,22 @@ export function PluginLoader({ plugins, children }: PluginLoaderProps) {
8589
});
8690

8791
await Promise.all(imports);
88-
setLoaded(true);
92+
if (!cancelled) {
93+
setLoaded(true);
94+
}
8995
} catch (error) {
9096
console.error('Failed to load plugins:', error);
91-
setLoaded(true); // Still render children even if plugin loading fails
97+
if (!cancelled) {
98+
setLoaded(true); // Still render children even if plugin loading fails
99+
}
92100
}
93101
};
94102

95103
loadPlugins();
104+
105+
return () => {
106+
cancelled = true;
107+
};
96108
}, [plugins]);
97109

98110
if (!loaded) {

0 commit comments

Comments
 (0)