-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Flow Builder iframe embed (POC) #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
db96b6f
72a0cae
07305c5
92b4cb4
eb271e9
177c63e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| title: "Build your flow" | ||
| description: "Design your flow and get the API calls for your exact use case" | ||
| mode: "custom" | ||
| "og:image": "/images/og/og-flow-builder.png" | ||
| --- | ||
|
|
||
| export const FlowBuilderEmbed = () => { | ||
| const [src, setSrc] = React.useState(null); | ||
|
|
||
| React.useEffect(() => { | ||
| const isDark = document.documentElement.classList.contains('dark'); | ||
| setSrc('https://grid-visualizer-opal.vercel.app/?embed=true&theme=' + (isDark ? 'dark' : 'light')); | ||
|
|
||
| let ignoreNextMutation = false; | ||
|
|
||
| const sendTheme = () => { | ||
| const t = document.documentElement.classList.contains('dark') ? 'dark' : 'light'; | ||
| const iframe = document.getElementById('flow-builder-iframe'); | ||
| if (iframe && iframe.contentWindow) { | ||
| iframe.contentWindow.postMessage({ type: 'theme-sync', theme: t }, '*'); | ||
| } | ||
| }; | ||
|
|
||
| const handleMessage = (e) => { | ||
| if (e.data && e.data.type === 'theme-request') { | ||
| sendTheme(); | ||
| return; | ||
| } | ||
| if (e.data && e.data.type === 'theme-sync') { | ||
| const isDark = document.documentElement.classList.contains('dark'); | ||
| const wantsDark = e.data.theme === 'dark'; | ||
| if (isDark !== wantsDark) { | ||
| ignoreNextMutation = true; | ||
| document.documentElement.classList.toggle('dark'); | ||
| } | ||
| } | ||
| }; | ||
|
Comment on lines
+25
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Message handler doesn't validate Prompt To Fix With AIThis is a comment left during a code review.
Path: mintlify/flow-builder.mdx
Line: 25-38
Comment:
Message handler doesn't validate `e.origin` before processing messages, allowing any site to send theme-sync commands. Add origin check like `if (e.origin !== 'https://grid-visualizer-opal.vercel.app') return;`.
How can I resolve this? If you propose a fix, please make it concise. |
||
| window.addEventListener('message', handleMessage); | ||
|
|
||
| const obs = new MutationObserver(() => { | ||
| if (ignoreNextMutation) { ignoreNextMutation = false; return; } | ||
| sendTheme(); | ||
| }); | ||
| obs.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] }); | ||
|
|
||
| return () => { | ||
| window.removeEventListener('message', handleMessage); | ||
| obs.disconnect(); | ||
| }; | ||
| }, []); | ||
|
Comment on lines
+11
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Context Used: Context from Prompt To Fix With AIThis is a comment left during a code review.
Path: mintlify/flow-builder.mdx
Line: 11-51
Comment:
Using `React.useEffect` breaks Mintlify's acorn parser per CLAUDE.md style guide. Replace with initialization code that doesn't use `useEffect`.
**Context Used:** Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=21abe025-35ab-4ae8-a4a1-0071c2ac3b98))
How can I resolve this? If you propose a fix, please make it concise.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong BTW, mintlify's own examples use useEffect https://www.mintlify.com/docs/customize/react-components#example-2 this was an old rule i added out of caution from a debugging session. i'll remove it |
||
|
|
||
| if (!src) return null; | ||
|
|
||
| return ( | ||
| <iframe | ||
| id="flow-builder-iframe" | ||
| src={src} | ||
| title="Grid Flow Builder" | ||
| allow="clipboard-write" | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| <div id="flow-builder-container"> | ||
| <FlowBuilderEmbed /> | ||
| </div> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
'*'as targetOrigin inpostMessageallows any window to receive the message. Should validate and use specific origin like'https://grid-visualizer-opal.vercel.app'.Prompt To Fix With AI