Skip to content

Commit ba1d743

Browse files
Copilothotlong
andcommitted
Fix fumadocs plugin preview by exporting types and loading plugins dynamically
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 08a5333 commit ba1d743

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

apps/site/app/components/InteractiveDemo.tsx

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React from 'react';
3+
import React, { useState, useEffect } from 'react';
44
import { SchemaRenderer } from '@object-ui/react';
55
import type { SchemaNode } from '@object-ui/core';
66
import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
@@ -9,6 +9,16 @@ import { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';
99
// Re-export SchemaNode type for use in MDX files
1010
export type { SchemaNode } from '@object-ui/core';
1111

12+
// Load plugins promise that we can await
13+
const pluginsLoading = typeof window !== 'undefined'
14+
? Promise.all([
15+
import('@object-ui/plugin-editor'),
16+
import('@object-ui/plugin-charts'),
17+
import('@object-ui/plugin-kanban'),
18+
import('@object-ui/plugin-markdown'),
19+
])
20+
: Promise.resolve([]);
21+
1222
interface InteractiveDemoProps {
1323
schema: SchemaNode;
1424
title?: string;
@@ -29,6 +39,15 @@ export function InteractiveDemo({
2939
description,
3040
examples
3141
}: InteractiveDemoProps) {
42+
const [pluginsLoaded, setPluginsLoaded] = useState(false);
43+
44+
useEffect(() => {
45+
// Wait for plugins to load before rendering
46+
pluginsLoading.then(() => {
47+
setPluginsLoaded(true);
48+
});
49+
}, []);
50+
3251
// If examples are provided, show a multi-example view
3352
if (examples && examples.length > 0) {
3453
return (
@@ -41,23 +60,27 @@ export function InteractiveDemo({
4160
)}
4261
<Tabs items={['Preview', 'Code']} defaultIndex={0}>
4362
<Tab value="Preview">
44-
<div className="space-y-6">
45-
{examples.map((example, index) => (
46-
<div key={index} className="border rounded-lg overflow-hidden">
47-
{example.label && (
48-
<div className="border-b bg-muted px-4 py-2">
49-
<p className="text-sm font-medium">{example.label}</p>
50-
{example.description && (
51-
<p className="text-xs text-muted-foreground mt-0.5">{example.description}</p>
52-
)}
63+
{!pluginsLoaded ? (
64+
<div className="p-6 text-center text-muted-foreground">Loading plugins...</div>
65+
) : (
66+
<div className="space-y-6">
67+
{examples.map((example, index) => (
68+
<div key={index} className="border rounded-lg overflow-hidden">
69+
{example.label && (
70+
<div className="border-b bg-muted px-4 py-2">
71+
<p className="text-sm font-medium">{example.label}</p>
72+
{example.description && (
73+
<p className="text-xs text-muted-foreground mt-0.5">{example.description}</p>
74+
)}
75+
</div>
76+
)}
77+
<div className="p-6 bg-background">
78+
<SchemaRenderer schema={example.schema} />
5379
</div>
54-
)}
55-
<div className="p-6 bg-background">
56-
<SchemaRenderer schema={example.schema} />
5780
</div>
58-
</div>
59-
))}
60-
</div>
81+
))}
82+
</div>
83+
)}
6184
</Tab>
6285
<Tab value="Code">
6386
<div className="space-y-4">
@@ -92,7 +115,11 @@ export function InteractiveDemo({
92115
<Tabs items={['Preview', 'Code']} defaultIndex={0}>
93116
<Tab value="Preview">
94117
<div className="border rounded-lg p-6 bg-background">
95-
<SchemaRenderer schema={schema} />
118+
{!pluginsLoaded ? (
119+
<div className="text-center text-muted-foreground">Loading plugins...</div>
120+
) : (
121+
<SchemaRenderer schema={schema} />
122+
)}
96123
</div>
97124
</Tab>
98125
<Tab value="Code">

apps/site/app/components/ObjectUIProvider.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ import { initializeComponents } from '@object-ui/components';
55
import { ComponentRegistry } from '@object-ui/core';
66
import { useEffect } from 'react';
77

8-
// Import plugins to register their component types
9-
import '@object-ui/plugin-editor';
10-
import '@object-ui/plugin-charts';
11-
import '@object-ui/plugin-kanban';
12-
import '@object-ui/plugin-markdown';
8+
// Dynamically import plugins only in browser context (not during SSR)
9+
if (typeof window !== 'undefined') {
10+
import('@object-ui/plugin-editor');
11+
import('@object-ui/plugin-charts');
12+
import('@object-ui/plugin-kanban');
13+
import('@object-ui/plugin-markdown');
14+
}
1315

1416
export function ObjectUIProvider({ children }: { children: React.ReactNode }) {
1517
// Explicitly call init to ensure components are registered
1618
useEffect(() => {
1719
initializeComponents();
18-
// Log registered components for debugging
19-
const componentTypes = ComponentRegistry.getAllTypes();
20-
console.log('[ObjectUIProvider] Registered components:', componentTypes);
20+
21+
// Wait a bit for plugins to register, then log
22+
setTimeout(() => {
23+
const componentTypes = ComponentRegistry.getAllTypes();
24+
console.log('[ObjectUIProvider] Registered components:', componentTypes);
25+
}, 100);
2126
}, []);
2227

2328
return <>{children}</>;

0 commit comments

Comments
 (0)