Skip to content

Commit b8e78f9

Browse files
authored
fix: issue with embeded not working correctly (#2245)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Fix embedded component issues by ensuring WASM readiness, updating layout, and removing placeholders in `clientwrapper.tsx`. > > - **Behavior**: > - Ensure WASM readiness before rendering in `EmbedComponentInner` in `clientwrapper.tsx`. > - Use fallback active file name 'main.baml' when WASM is not ready in `clientwrapper.tsx`. > - Add `dev:fiddle-web-app` script to `package.json`. > - **Components**: > - Wrap `EmbedComponentInner` with `JotaiProvider` in `clientwrapper.tsx`. > - Remove placeholder `JotaiProvider` and `PromptPreview` components in `clientwrapper.tsx`. > - Add `PromptPreview` and `JotaiProvider` imports in `clientwrapper.tsx`. > - **Layout**: > - Add `viewport` export to `layout.tsx` for theme color settings. > - Update `body` class in `layout.tsx` to include new font and styling classes. > - **Dependencies**: > - Add `geist` dependency to `fiddle-web-app/package.json`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for c6847fc. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 75f3e2a commit b8e78f9

6 files changed

Lines changed: 77 additions & 42 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dev:vscode": "turbo run dev --filter=baml-extension...",
1717
"dev:language-server": "turbo run dev --filter=@baml/language-server",
1818
"dev:playground": "turbo run dev --filter=@baml/playground",
19+
"dev:fiddle-web-app": "turbo run dev --filter=@baml/fiddle-web-app...",
1920
"generate": "turbo run generate",
2021
"typecheck": "turbo run typecheck",
2122
"lint:ws": "pnpm dlx sherif@latest",

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/apps/fiddle-web-app/app/embed/clientwrapper.tsx

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use client';
2-
import { filesAtom } from '@baml/playground-common';
2+
import { filesAtom, useWaitForWasm } from '@baml/playground-common';
3+
import { PromptPreview } from '@baml/playground-common/prompt-preview';
4+
import { JotaiProvider } from '@baml/playground-common/jotai-provider';
35
import { ResizableHandle, ResizablePanelGroup } from '@baml/ui/resizable';
46
import { ResizablePanel } from '@baml/ui/resizable';
57
import { ScrollArea } from '@baml/ui/scroll-area';
@@ -60,10 +62,6 @@ const CustomErrorBoundary: React.FC<{ children: React.ReactNode; message?: strin
6062
};
6163

6264
// Placeholder components
63-
const JotaiProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
64-
return <>{children}</>;
65-
};
66-
6765
const CodeMirrorViewer: React.FC<any> = ({ fileContent, onContentChange }) => {
6866
return (
6967
<textarea
@@ -74,14 +72,6 @@ const CodeMirrorViewer: React.FC<any> = ({ fileContent, onContentChange }) => {
7472
);
7573
};
7674

77-
const PromptPreview: React.FC = () => {
78-
return (
79-
<div className="flex items-center justify-center w-full h-full">
80-
<p className="text-muted-foreground">Prompt preview coming soon...</p>
81-
</div>
82-
);
83-
};
84-
8575
const EventListener: React.FC = () => {
8676
return null;
8777
};
@@ -92,9 +82,21 @@ interface EmbedComponentProps {
9282
}
9383

9484
export default function EmbedComponent({ bamlContent }: EmbedComponentProps) {
85+
return (
86+
<JotaiProvider>
87+
<EmbedComponentInner bamlContent={bamlContent} />
88+
</JotaiProvider>
89+
);
90+
}
91+
92+
function EmbedComponentInner({ bamlContent }: EmbedComponentProps) {
9593
const [files, setFiles] = useAtom(filesAtom);
9694
const [isLoading, setIsLoading] = useState(true);
97-
const activeFileName = useAtomValue(activeFileNameAtom);
95+
const isWasmReady = useWaitForWasm();
96+
const activeFileNameAtomValue = useAtomValue(activeFileNameAtom);
97+
98+
// Use fallback active file name when WASM is not ready
99+
const activeFileName = isWasmReady ? activeFileNameAtomValue : 'main.baml';
98100

99101
useEffect(() => {
100102
// Set the files with the BAML content passed from the server
@@ -104,7 +106,8 @@ export default function EmbedComponent({ bamlContent }: EmbedComponentProps) {
104106
setIsLoading(false);
105107
}, [bamlContent, setFiles]);
106108

107-
if (isLoading) {
109+
// Wait for WASM to be ready before rendering
110+
if (isLoading || !isWasmReady) {
108111
return <div className="text-white">Loading BAML file...</div>;
109112
}
110113

@@ -120,29 +123,27 @@ export default function EmbedComponent({ bamlContent }: EmbedComponentProps) {
120123
direction="horizontal"
121124
>
122125
<ResizablePanel defaultSize={50}>
123-
<div className="flex pl-1 w-full h-full tour-editor dark:bg-muted/70">
124-
<ScrollArea className="w-full h-full">
125-
{activeFileName && (
126-
<CodeMirrorViewer
127-
lang="baml"
128-
fileContent={{
129-
code: files[activeFileName] || '',
130-
language: 'baml',
131-
id: activeFileName,
132-
}}
133-
hideLineNumbers={true}
134-
shouldScrollDown={false}
135-
onContentChange={(v: string) => {
136-
const newFiles: Record<string, string> = {};
137-
Object.entries(files).map(([key, value]) => {
138-
const newVal = key === activeFileName ? v : value;
139-
newFiles[key] = newVal;
140-
});
141-
setFiles(newFiles);
142-
}}
143-
/>
144-
)}
145-
</ScrollArea>
126+
<div className="flex pl-1 w-full h-full tour-editor dark:bg-muted/70 overflow-y-auto">
127+
{activeFileName && (
128+
<CodeMirrorViewer
129+
lang="baml"
130+
fileContent={{
131+
code: files[activeFileName] || '',
132+
language: 'baml',
133+
id: activeFileName,
134+
}}
135+
hideLineNumbers={true}
136+
shouldScrollDown={false}
137+
onContentChange={(v: string) => {
138+
const newFiles: Record<string, string> = {};
139+
Object.entries(files).map(([key, value]) => {
140+
const newVal = key === activeFileName ? v : value;
141+
newFiles[key] = newVal;
142+
});
143+
setFiles(newFiles);
144+
}}
145+
/>
146+
)}
146147
</div>
147148
</ResizablePanel>
148149
<ResizableHandle className="" />

typescript/apps/fiddle-web-app/app/layout.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Toaster } from '@baml/ui/sonner';
2-
import type { Metadata } from 'next';
2+
import type { Metadata, Viewport } from 'next';
33
import { Inter } from 'next/font/google';
44
import { Suspense } from 'react';
55
import { ErrorBoundary } from 'react-error-boundary';
66
import { PHProvider, RB2BElement } from './_components/PosthogProvider';
77
import { ThemeProvider } from './_components/ThemeProvider';
88
import '@baml/ui/globals.css';
99
import PostHogPageView from './PostHogPageView';
10+
import { cn } from '@baml/ui/lib/utils';
11+
12+
import { GeistMono } from 'geist/font/mono';
13+
import { GeistSans } from 'geist/font/sans';
1014

1115
const inter = Inter({ subsets: ['latin'] });
1216

@@ -15,16 +19,31 @@ export const metadata: Metadata = {
1519
description: 'An LLM prompt playground for structured prompting',
1620
};
1721

22+
export const viewport: Viewport = {
23+
themeColor: [
24+
{ color: 'white', media: '(prefers-color-scheme: light)' },
25+
{ color: 'black', media: '(prefers-color-scheme: dark)' },
26+
],
27+
};
28+
1829
export default function RootLayout({
1930
children,
2031
}: Readonly<{
2132
children: React.ReactNode;
2233
}>) {
2334
return (
24-
<html lang="en">
35+
<html lang="en" suppressHydrationWarning>
36+
37+
2538
<RB2BElement />
2639
<PHProvider>
27-
<body className={'bg-background'}>
40+
<body
41+
className={cn(
42+
'bg-background text-foreground relative min-h-screen font-sans antialiased',
43+
GeistSans.variable,
44+
GeistMono.variable,
45+
)}
46+
>
2847
<ErrorBoundary fallback={<div></div>}>
2948
<PostHogPageView />
3049
</ErrorBoundary>

typescript/apps/fiddle-web-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react-arborist": "3.4.3",
3333
"react-device-detect": "2.2.3",
3434
"react-dom": "19.1.0",
35+
"geist": "1.4.2",
3536
"react-error-boundary": "6.0.0",
3637
"react-icons": "5.5.0",
3738
"react-joyride": "2.9.3",

typescript/packages/playground-common/src/shared/baml-project-panel/atoms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,4 @@ export const proxyUrlAtom = atom((get) => {
192192
proxyEnabled,
193193
proxyUrl,
194194
};
195-
});
195+
});

0 commit comments

Comments
 (0)