惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
T
The Blog of Author Tim Ferriss
量子位
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
小众软件
小众软件
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
I
InfoQ
美团技术团队
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
IT之家
IT之家
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I built /ai inside a notes app — here's how I render gene...
Memduh PANPA · 2026-05-27 · via DEV Community

I take a lot of notes while I'm working. Meeting notes, quick ideas, system design sketches — all of it ends up somewhere.

The frustrating part was never writing the notes. It was what happened after. I'd describe a UI idea in a note — a color picker, a calculator, a data formatter — and then I'd have to open a separate editor, build the thing, test it, and come back. The note and the tool lived in completely different places.

At some point I thought: what if the tool just lived inside the note?

That's what I've been building for the past few weeks. You type /ai in the editor, describe what you want, and a working interactive component appears inside your document. Not a screenshot. Not a code block. A real, running UI.

Here's what that looks like mid-generation:

Fluxerv AI generating a component in real time

This is the streaming moment — the AI is writing the component live, and it appears inside the note as it generates.

Let me walk through how I built this.


The editor foundation

I'm using Tiptap — a headless, extensible rich text editor for React. Tiptap is built on ProseMirror, which means you can define custom nodes: blocks that behave however you want inside the document.

I created a custom AiNode — a Tiptap node that holds generated HTML/CSS/JS as a string in its attributes. When the node renders, it shows a live iframe. The node persists to Supabase as part of the document's JSON content.

const AiNodeExtension = Node.create({
  name: 'aiComponent',
  group: 'block',
  atom: true,
  addAttributes() {
    return {
      code: { default: '' },
      prompt: { default: '' },
    }
  },
  // ...
})

Enter fullscreen mode Exit fullscreen mode

Simple enough. The hard part was getting the code into the node while streaming.


The streaming problem

The AI backend uses Gemini 2.5 Flash via Server-Sent Events. The model streams the HTML, CSS, and JS as one big string — character by character.

The problem: I needed to show this output live inside the Tiptap node while it was still being generated. Users shouldn't stare at a spinner for 10 seconds.

My first approach was to update the rendered output on every streamed chunk. It worked, but it caused too many re-renders and made the editor feel heavy.

The better approach was to decouple streaming from rendering: accumulate the generated code in a ref while the stream is active, then render the final result once inside a sandboxed iframe.

const accumulated = useRef('')

// On each chunk:
accumulated.current += chunk

// On stream close:
editor.commands.updateAttributes('aiComponent', {
  code: accumulated.current
})

Enter fullscreen mode Exit fullscreen mode

The node re-renders once, the iframe appears, the component runs.


The sandbox setup

The iframe uses this sandbox configuration:

<iframe
  sandbox="allow-scripts"
  srcdoc={generateSrcdoc(code)}
/>

Enter fullscreen mode Exit fullscreen mode

Notice what's missing: allow-same-origin.

This is intentional and critical. Without allow-same-origin, the iframe cannot access localStorage, cookies, or the parent document's DOM. The AI-generated code runs in complete isolation. It can't read your tokens, it can't exfiltrate data, it can't touch anything outside its own sandbox.

allow-scripts alone is enough for interactive components to work — timers, event listeners, DOM manipulation inside the frame, all fine.

I also inject Tailwind CSS via CDN inside the iframe's srcdoc so generated components can use utility classes without any build step:

function generateSrcdoc(code) {
  return `
    <!DOCTYPE html>
    <html>
      <head>
        <script src="https://cdn.tailwindcss.com"></script>
        <style>
          body { background: #09090b; margin: 0; padding: 16px; }
        </style>
      </head>
      <body>${code}</body>
    </html>
  `
}

Enter fullscreen mode Exit fullscreen mode


The refine system

Once a component is generated, users can update it with natural language. There's a "Refine" button in the component toolbar. You type something like "make the background darker" or "add a reset button" — and the component updates.

The naive approach would be to regenerate the entire component from scratch. That works but it's slow and wasteful.

Instead, I built a /api/edit endpoint that receives two things: the current component code and the edit instruction. The system prompt wraps them together:

You are editing an existing UI component.

Current code:
[CURRENT_CODE]

Edit instruction:
[INSTRUCTION]

Return only the updated full component code. No explanations.

Enter fullscreen mode Exit fullscreen mode

The model returns the full updated component — but it only needs to reason about the delta. In practice this is faster and produces more coherent edits than full regeneration.

The response streams the same way as generation, and the node updates when it's done.


What I got wrong

A few things that cost me time:

Stale closures in Tiptap. If you reference editor inside a useEffect without including it in the dependency array, you'll be working with a stale editor instance. Commands will silently fail. This one took a while to track down.

Rate limiting before you think you need it. I added Upstash Redis rate limiting to both endpoints early on. Good call — during testing I hit Gemini's limits faster than expected. Shared rate limiter utility across both endpoints so I wasn't duplicating logic.

The middleware gap. My Next.js middleware was redirecting unauthenticated users to login — including the /share/ route for public documents and the /api/ routes. Had to explicitly whitelist these paths. Simple fix, annoying to debug.


Where it is now

The app is called Fluxerv. It's a workspace where your documents can contain live, interactive tools — not just text.

Here's a 2-minute demo of it generating a pomodoro timer from a single prompt:

The stack: Next.js (App Router), Tiptap v3, Supabase, Gemini 2.5 Flash (starting point — will scale up as needed), Tailwind CSS, Upstash Redis.

It's currently in private beta. If you want early access when it opens, follow me on Twitter — I post build updates there.

@MPanpalli on X/Twitter


If you've built something similar or ran into the same iframe/streaming problem, I'd love to hear how you solved it. Drop a comment.