{"slug": "rebuilding-deepseek-chat-with-solidjs-and-putting-ew-solid-ui-through-the", "title": "Rebuilding DeepSeek Chat with SolidJS — and putting ew-solid-ui through the wringer", "summary": "A developer rebuilt DeepSeek's chat demo in SolidJS using the ew-solid-ui 0.0.9/0.0.10 component library to stress-test it against real product conditions rather than isolated Storybook pages. The demo reproduces streaming replies, deep thinking, web search, message branching, Markdown/math/Mermaid rendering, attachments, voice input, and mobile safe areas, with the browser calling api.deepseek.com directly using a user-supplied API key. The developer reports the library held up, with a few issues surfacing only under the dense, high-frequency streaming workload.", "body_md": "By the time ew-solid-ui reached 0.0.9 it had docs, examples, and a green test suite, which sounds reassuring until you remember what those things actually prove. A button on its own page. A modal on another page. A select on a third. Everything evenly spaced, everything well behaved. Of course nothing breaks.\n\nStorybook is not where a component library gets tested. A real product is: a select inside a modal, a button hanging off the right edge of an input, streamed text arriving every few dozen milliseconds, the theme flipping, a phone keyboard eating half the viewport. That's the exam.\n\nSo I went looking for a real project to throw at it. Another admin dashboard was pointless — those pages are mostly tables, and tables don't stress anything. In the end I picked DeepSeek's chat demo.\n\nThe reasoning was practical. It's dense enough to hit nearly every weak spot a component library has, and it comes with a finished design, so spacing, radii, and colors are already decided. I wouldn't waste time second-guessing visuals; all of it could go into one question.\n\n| What I wanted to test | Where the demo exercises it | \n|---|---|\n| Can CSS variables absorb an entire external theme? | The official `--dsw-*` token set, plus light/dark switching | \n| Do nested overlays fight each other? | A select for language, voice, and region inside the settings modal | \n| Can a composer be reshaped by the business layer? | Attachment strip, toggle row, recording spectrum, drag overlay | \n| Does it survive high-frequency streaming updates? | Token-level Markdown with math and Mermaid inside | \n| Does mobile fall apart? | `visualViewport` , keyboard insets, safe areas | \n\nThat's how this project started. The short version of how it ended: the library held up, but a few things only showed themselves in a page like this. What follows is the order I hit them, including how each one was found.\n\nTwo live URLs: [ds-chat.eveningwater.com](https://ds-chat.eveningwater.com), or the [GitHub Pages build](https://eveningwater.github.io/ew-solid-ui-deepseek-chat-demo/). You paste a DeepSeek API key into settings first. The browser calls `https://api.deepseek.com` directly; there's no server of mine in the middle.\n\nFeature-wise I copied the official demo: streaming replies, deep thinking, web search, continue, regenerate, edit prompt; message branches with version switching; Markdown, code blocks, math, Mermaid, citation chips; image and document attachments with drag, paste, and retry; voice input and read-aloud; session list with rename, delete, and ZIP import/export; light and dark themes, Chinese and English, mobile safe areas.\n\nThe stack is nothing to show off:\n\n| Concern | Choice | \n|---|---|\n| Build / language | Vite 6 + TypeScript 5.7 | \n| Framework | SolidJS 1.9 (fine-grained reactivity, no virtual DOM) | \n| Component library | ew-solid-ui 0.0.10 | \n| State | `createMemoryStore` from`ew-solid-ui/headless` | \n| Storage | IndexedDB (sessions/attachments) + localStorage (settings) | \n| Content rendering | ew-solid-ui Markdown + KaTeX + Mermaid + Prism | \n\n`idb`, `fflate`, KaTeX, Mermaid, and Prism are just tools. They have nothing to do with whether I use the component library, so they went in where needed. No zustand for state, no second UI library. That's the whole dependency story.\n\n```\nsrc/\n├── app/           page shell: App, theme, viewport, global styles\n├── components/\n│   ├── chatInput/ input, draft attachments, voice, spectrum, drag overlay\n│   ├── files/     file icons, file cards, preview hook\n│   ├── markdown/  Markdown adapter, code block, math, Mermaid, links\n│   ├── messages/  message list, user/assistant messages, thinking and search steps\n│   ├── search/    search results panel, source cards, citation chips\n│   ├── session/   welcome page, session page, mobile top bar\n│   ├── settings/  settings modal, API Key form\n│   └── sider/     sidebar, session item, mobile drawer\n├── i18n/          Chinese and English copy\n├── services/      api / chat / markdown / speech, settings and attachments\n└── utils/\n```\n\nOnly one rule matters: **anything generic comes from the library; anything that only exists because this is a chat app I write myself.**\n\nGeneric: Button, Icon (the multi-color drag-and-drop illustration is `upload-picture` from the library), Tooltip, Dropdown, Modal, Select, the various fields, Popover, Welcome, Markdown, Toast, plus headless `useCopy` and `createMemoryStore`. Specific: the composer, message timeline, attachment cards, citation preprocessing, SSE, persistence, recording.\n\nKeep that line and you never end up cramming chat logic into a generic component just to prove you used the dependency.\n\nRendering isn't the hard part of a chat page. State is. Streaming output, upload progress, the session list, and the settings panel all change independently, and one sloppy move re-renders the world.\n\n`createMemoryStore` in `ew-solid-ui/headless` covered it, so zustand never got installed:\n\n``` js\nimport { createMemoryStore } from 'ew-solid-ui/headless'\n\nexport const useChatStore = createMemoryStore<ChatState>({\n  ready: false,\n  sessions: [],\n  activeId: null,\n  streaming: {},\n})\n```\n\nIt keeps zustand's `getState` / `setState` and adds `replaceState`. Three things mattered in practice.\n\nReading `state.xxx` subscribes you automatically, and only top-level fields are tracked. Importing history flips `importingHistory`, and the sidebar — which only reads `sessions` — doesn't flinch. That's nice. `setState` is a shallow merge and an empty patch notifies nobody, so nested objects have to be replaced wholesale. I didn't believe that at first and mutated `streaming[id].status` in place. The page didn't move. I stared at it for a while before remembering how shallow merge works. And `getState()` gives you a plain snapshot, so it can go straight into IndexedDB or `JSON.stringify` without proxy-clone surprises.\n\n`useChatStore`, `useSettings`, `useUploads`, `useReadAloud`, `useSearchPanel`, `useMobileSider`, and `useSettingsDialog` are all built on it.\n\n| Component | Where | \n|---|---|\n| `Button` | Sidebar, settings, message actions, modal footers | \n| `Icon` | Everywhere | \n| `Tooltip` | Composer toggles, voice, retry, sidebar collapse | \n| `Dropdown` | The \"more\" menu on a session | \n| `Modal` | Settings, delete confirmation, import confirmation | \n| `Select` | Language, voice, region, province, city | \n| `InputField` | Session rename | \n| `PasswordField` | API Key input | \n| `TextareaField` | Editing a prompt, and the composer body | \n| `Welcome` | New-conversation screen | \n| `Markdown` | Message body | \n| `Popover` | Source card behind a citation chip | \n| `Toasts` +`toast` | Global notifications | \n| `useCopy` | Copy buttons, code blocks | \n| `createMemoryStore` | All shared state | \n\nEverything comes from the package root except the headless pieces, which live under `/headless`:\n\n``` js\nimport {\n  Button, Icon, Tooltip, Dropdown, Modal, Select,\n  InputField, PasswordField, TextareaField,\n  Welcome, Popover, Toasts, toast,\n} from 'ew-solid-ui'\nimport { createMemoryStore, useCopy } from 'ew-solid-ui/headless'\n```\n\n`Toasts` is mounted once in `main.tsx`. Business code only ever calls `toast.error(...)`; the container and animations are none of its business.\n\nSymptom: the send button was brown. The demo's is blue. Nothing I did turned it blue. Time to look.\n\nFirst suspicion, obviously, was that `--ew-accent` wasn't taking effect. DevTools said the value was exactly what I wrote. The button stayed brown. So I went digging through the stylesheet and found a second layer, `--ewcp-*`, already declared on `:root`:\n\n```\n:root {\n  --ewcp-color-primary: var(--ew-accent);\n}\n```\n\nThat's when it clicked. **A custom property is resolved on the element where it is declared, not where you override it.** `:root` is evaluated before `body`, so it picked up the library's default brown and inherited it down to everything. My blue `--ew-accent` on `body` was invisible to it.\n\nThe fix is unglamorous — re-point that layer on `body` too:\n\n```\nbody {\n  --ewcp-color-primary: var(--ew-accent);\n  --ewcp-color-primary-hover: var(--ew-accent-strong);\n  --ewcp-color-text: var(--ew-ink);\n  --ewcp-color-border: var(--ew-line-strong);\n  --ewcp-color-bg: var(--ew-card);\n  --ewcp-radius-sm: var(--ew-radius-sm);\n}\n```\n\nSave. Blue. That's it? Yes, that's it — and I spent a good half hour doubting my CSS skills first.\n\nThe theme mapping itself lives at the end of `src/app/theme.css`, `--dsw-*` onto `--ew-*`:\n\n```\nbody {\n  --ew-accent: var(--dsw-alias-brand-primary);\n  --ew-card: var(--dsw-alias-bg-base);\n  --ew-ink: var(--dsw-alias-label-primary);\n  --ew-ink-soft: var(--dsw-alias-label-secondary);\n  --ew-muted: var(--dsw-alias-label-tertiary);\n  --ew-line: var(--dsw-alias-border-l2);\n  --ew-line-strong: var(--dsw-alias-border-l3);\n  --ew-fill: var(--dsw-alias-interactive-bg-hover);\n}\n```\n\nFlip `body.light` / `body.dark` and buttons, inputs, modals, and dropdowns follow. No duplicate styles per component.\n\nIn `main.tsx`, styles have to be imported before the business components:\n\n``` js\nimport { render } from 'solid-js/web'\nimport { Toasts } from 'ew-solid-ui'\nimport 'ew-solid-ui/styles.css'\nimport './app/theme.css'\nimport './app/global.css'\nimport { App } from './app/App'\n\nrender(() => (<><App /><Toasts /></>), document.getElementById('root') as HTMLElement)\n```\n\nVite injects CSS in module evaluation order. Put `import { App }` first and the CSS Modules load first; the library's stylesheet arrives afterwards and quietly overwrites them.\n\nWhat makes this one nasty: **your rule is in the file, DevTools shows it, and it does nothing.** Send button height, settings dialog width, theme card radius — each broke this way at some point. I now check `main.tsx` import order before touching styles, which saves me from doubting my own sanity.\n\nThe overrides themselves aren't clever. Layout lives under my own class names; component internals get precise `:global(.ew-*)` edits; nothing gets copied wholesale.\n\n```\n.apiKeyInput :global(.ew-field__control),\n.apiKeyInput :global(.ew-field__control:focus-within) {\n  height: 100%;\n  border: none;\n  background: transparent;\n  box-shadow: none;\n}\n```\n\nSometimes specificity has to be doubled. `.sendButton` alone loses to `.ewcp-button--small`, so the send button uses `.sendButton.sendButton`. It's ugly. It works.\n\nThe welcome screen uses `Welcome` as a container, title from props, composer in `extra`, with the library's icon and description hidden:\n\n```\n<WelcomeArea\n  class={styles.welcome}\n  title={t('welcomeMessageChat250808')}\n  extra={<ChatInput sessionId={null} />}\n/>\n```\n\nThe settings dialog lets `Modal` own the portal, backdrop, Esc, and focus, while navigation and content stay mine. The library defaults to `max-width: 520px` and the demo is 760×500, so the business class overrides it — no forking the component:\n\n```\n.dialog {\n  width: 760px;\n  height: 500px;\n  max-width: calc(100vw - 32px);\n  padding: 19px 24px 22px;\n}\n```\n\nThe API key input puts the confirm button in `PasswordField`'s `suffix` slot:\n\n```\n<PasswordField\n  value={form.value()}\n  suffix={\n    <Show when={value.trim()}>\n      <span class={styles.divider} />\n      <Button variant=\"link\" onClick={submit}>OK</Button>\n    </Show>\n  }\n/>\n```\n\nCheaper than wrapping an input and a button in a div, and the focus ring, disabled state, and password visibility are already handled.\n\nCopying uses `useCopy` instead of a hand-rolled clipboard fallback:\n\n```\nconst { copied, copy } = useCopy({ duration: 1000 })\n\nif (!(await copy(text))) {\n  showToast({ key: 'copyFailed' })\n}\n```\n\nThe icon flips between `copy` and `check` on `copied()`, and failures go through a toast.\n\n`Sender`\nThere's a ready-made `Sender` that covers an entire chat input and should, in theory, drop right in. The demo's composer is too weird for it: attachment strip, toggle row, recording spectrum, drag overlay, per-file upload state, all inside one rounded box. `Sender`'s slots can't hold that, and fighting it would have cost more than building it.\n\nSo only `TextareaField` got used, for the body. It fits: `autoResize` with `minRows` / `maxRows` replaces the mirror-div height measurement, and `value` / `onInput` / `onKeyDown` are properly controlled.\n\nThe one annoyance is that it doesn't expose the textarea ref. Voice transcription inserts at the caret, desktop needs autofocus, and paste needs to read files — all three need the native element. So I ended up with `querySelector('textarea')` on the container, used in exactly those three places and nowhere else. It works. It isn't clean, and I'll come back to it.\n\nThe call chain isn't long:\n\n```\nChatInput.send()\n  → chat/store.sendMessage()\n  → services/api/client (POST /anthropic/v1/messages)\n  → services/api/sse (byte stream → text → SSE events)\n  → services/api/parseEvent (thinking / text / tool_use / usage)\n  → chat/store updates sessionCache\n  → MessageList / ReplyArea / Markdown update automatically\n```\n\nThe SSE parser is written by hand against the WHATWG spec: incremental UTF-8 decoding, CRLF/LF/CR line splitting, accumulating `event` / `data` / `id`, dispatching on a blank line, ignoring keep-alive comments. I couldn't just grab a library, because `fetch` hands you a `ReadableStream` and a lot of SSE packages only speak `EventSource`.\n\nThe store holds little: `sessions` (summaries), `sessionCache` (the active conversation's full messages), `streaming` (which sessions are mid-stream), two error fields for persistence failures, and `importingHistory` to lock the composer during import.\n\nAssistant messages aren't rendered raw. They go through `buildReplyView` first: thinking blocks, tool calls, and search results become timeline steps; text blocks get merged; citation sources (`Source[]`) and search panel data are computed; error, stopped, and safety-refusal states are normalized.\n\n`useReplyView` reuses the previous sources array when the content hasn't changed. Otherwise every streamed token creates a new array reference and forces Markdown to re-parse. Pure waste.\n\nThe chain:\n\n```\nstreamed text\n  → useThrottleMarkdownRender (throttle derived from the last render's cost)\n  → preprocessMarkdown (only [citation:N] and <br>)\n  → ew-solid-ui Markdown (marked lexer + Solid renderer)\n  → components (CodeBlock / MathBlock / InlineMath / CitationLink)\n```\n\nPreprocessing does two things, and it skips fenced and inline code so sample snippets don't get mangled.\n\nMath was a detour. I wrote my own `$...$` extraction first, then discovered the library's Markdown already handles `$...$`, `$$...$$`, `\\(...\\)`, and `\\[...\\]`, calling back through `mathInline` / `mathBlock`. The business side only has to run KaTeX. So my preprocessing was pointless. Deleted. Time spent for nothing.\n\nCitations work the same way: `[citation:N]` becomes `[N]`, the `citation` hook receives the index and looks up the source, and nothing renders when there isn't one. The library's citation detection skips `[N](url)`, so ordinary links survive.\n\nTables, lists, headings, paragraphs, code blocks, inline code, and images are all handled by the library's lexer and renderer. I only replace nodes that need customizing, through `components`.\n\nStreaming states get their own handling: an unclosed formula keeps the last successful render, Mermaid draws only complete lines and defers errors until the stream ends, Prism language packs load on demand with a plain-text fallback. Copy and the Mermaid/code toggle use `Button` + `Icon` + `useCopy`.\n\nAttachments sit in two layers. Draft files live in `draftMap` so the composer can show upload progress inline; after sending they're written to IndexedDB and the message keeps only a file ID.\n\nThe upload state machine is in `services/attachments.ts`: `queued → uploading → done`, with `error` splitting into retryable and terminal. Previews come from `useFileView`, which reads a Blob from the File or IndexedDB and builds a `blob:` URL; SVG goes through a data URL to stay isolated. Cards, thumbnails, retry, delete — all business components, with library buttons and icons inside.\n\nVoice records with `MediaRecorder` next to an `AudioContext` and `AnalyserNode`. The spectrum reads frequency data every frame, maps it onto logarithmic bands, and writes `transform` directly instead of going through reactivity. Why? Sixty re-renders per second would hurt even Solid. The clip then goes to the server for transcription and the text lands at the caret. Read-aloud is centralized in `services/speech/readAloud.ts` and stops when the message changes.\n\nPersistence is ordinary: settings in localStorage, sessions and attachments in IndexedDB, export as session JSON plus attachments in a ZIP. Import understands DeepSeek's export format and overwrites local sessions, hence the confirmation and progress. Import also locks the composer and cancels speech; otherwise the two flows race for state and strange things happen.\n\nOne note on mobile: the sidebar is a drawer, fixed on desktop; the settings dialog becomes a bottom sheet on phones. `useIsMobile` is just `matchMedia('not all and (min-width: 768px)')`, `useMobileViewport` follows `visualViewport` so the top bar and composer stay visible when the keyboard opens, and `usePreventPageScroll` kills whole-page scrolling while preserving inner scroll areas and pinch zoom. Without that the page feels bolted shut.\n\nStreaming Markdown is throttled against the previous render's cost rather than a fixed interval. A fixed interval is either laggy or wasteful; the adaptive version made long answers visibly smoother.\n\nThe message list follows the bottom only within 40px, and stops as soon as you scroll up on purpose. After switching branches, scroll position is restored relative to the version selector, so answers of different lengths don't make the page jump. That one was annoying enough to fix properly.\n\nPrism, Mermaid, and KaTeX all load lazily. On the library side I import only what's used and let Vite tree-shake the rest.\n\nFinding problems was the point, so this section is more useful than everything above it.\n\n`TextareaField` doesn't expose a ref\nSo I `querySelector('textarea')`. That's my implementation flaw and the library's design flaw. A component should hand out its native element or a ref; business code shouldn't reverse-engineer DOM structure. Easy to fix, and it's on the next version's list.\n\n`--ewcp-*` resolves on `:root`\nThat's a variable-layering limitation. If the internal layer inherited, or were declared with `:where()`, one override on the business side would be enough, and \"why is the button brown\" would never become an incident.\n\n`:global(.ew-*)` works, but it's dirty. It asks the consumer to remember things like `.ew-field__control`, and a rename inside the library breaks it. More semantic slots and more CSS variables would beat making people guess at internals.\n\nIt went unused here, which says enough. Real chat inputs grow an attachment strip and a status row, and two slots named `header` and `footer` genuinely can't absorb that.\n\nAll four are on my todo list, and I'll pick them off in the next release.\n\nWhile I was writing this up, the library published 0.0.10 and fixed one of the items on my list: in standalone mode, `Spin` dropped the `class` prop, applying it only on the wrapper branch. The casualty was the streaming waiting state, which was three spans and twenty lines of hand-written CSS.\n\nAfter the fix, one line does it:\n\n```\n<Show when={waiting()}>\n  <Spin variant=\"dots\" class={styles.waiting} />\n</Show>\n```\n\nWhat's left in CSS is two layers: the outer class restores the demo's size, gap, and color, and the inner rule replaces the library's bounce with the demo's opacity fade. Three spans and `.waitingDot` are gone, the animation is unchanged, and there's less code.\n\nThe same release made the `CodeBlock` highlighter pluggable, so `createPrismHighlighter(Prism)` can wire Prism straight in. I didn't switch, because highlighting is synchronous and can't wait for a lazily imported language pack, and there's still no header slot for the Mermaid diagram/code toggle. Neither is a styling problem, so the custom code block stays.\n\nOne observation worth keeping: a verification project that pushes fixes back into the library is worth more than ten Storybook stories.\n\n```\npnpm install\npnpm dev        # http://localhost:8090\npnpm typecheck\npnpm build\n```\n\nYou need a DeepSeek API key in settings on first launch. The endpoint comes from `__API_ORIGIN__` in `vite.config.ts`, defaulting to `https://api.deepseek.com`; change that one line if you want a proxy.\n\nThe value of this project isn't how faithfully it copies DeepSeek. It's that it proves something concrete: **a Solid app with no React, no zustand, and every piece of UI coming from a self-maintained component library can carry a page with this much interaction density.**\n\nIt also put the library's weak spots under a lamp — variable layering, ref passthrough, slot design. None of that shows up in Storybook. It only surfaces after a week of being dragged through real work.\n\nOne-line summary: **a component library isn't good because it looks good in a demo; it's good if it's still standing after the business is done with it.**\n\nThat's it from me. Go poke at the [demo](https://ds-chat.eveningwater.com) if you feel like it, and open an issue if something's off.", "url": "https://wpnews.pro/news/rebuilding-deepseek-chat-with-solidjs-and-putting-ew-solid-ui-through-the", "canonical_source": "https://dev.to/eveningwater/rebuilding-deepseek-chat-with-solidjs-and-putting-ew-solid-ui-through-the-wringer-1o1d", "published_at": "2026-12-04 08:11:33+00:00", "updated_at": "2026-12-04 08:16:06.826146+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-products", "generative-ai"], "entities": ["DeepSeek", "SolidJS", "ew-solid-ui", "Vite", "TypeScript", "KaTeX", "Mermaid", "Prism"], "also_reported_by": [], "takeaway": "Stress-test a component library by rebuilding a dense real product like DeepSeek's chat demo, which exercises nested overlays, CSS-variable theming, high-frequency streaming Markdown, and mobile viewport insets that isolated Storybook pages never hit.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/rebuilding-deepseek-chat-with-solidjs-and-putting-ew-solid-ui-through-the", "markdown": "https://wpnews.pro/news/rebuilding-deepseek-chat-with-solidjs-and-putting-ew-solid-ui-through-the.md", "text": "https://wpnews.pro/news/rebuilding-deepseek-chat-with-solidjs-and-putting-ew-solid-ui-through-the.txt", "jsonld": "https://wpnews.pro/news/rebuilding-deepseek-chat-with-solidjs-and-putting-ew-solid-ui-through-the.jsonld"}}