Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(assistant): preserve ordered list numbering across split ol elements (#42521)

Matt Rossman91ffdda3ea97
diff --git a/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.test.tsx b/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.test.tsx
new file mode 100644
index 00000000000..c78f8b48b9c
--- /dev/null
+++ b/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.test.tsx
@@ -0,0 +1,17 @@
+import { render } from '@testing-library/react'
+import { describe, expect, test } from 'vitest'
+import { OrderedList } from './MessageMarkdown'
+
+describe('OrderedList', () => {
+ test('sets counter-reset based on start prop for split lists', () => {
+ const { container } = render(
+ <OrderedList start={3}>
+ <li>Third item</li>
+ </OrderedList>
+ )
+ const ol = container.querySelector('ol')
+ expect(ol).toBeInTheDocument()
+ expect(ol).toHaveAttribute('start', '3')
+ expect(ol).toHaveStyle({ counterReset: 'item 2' })
+ })
+})
diff --git a/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsx b/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsx
index 1e26e1befc2..8ecf0ee4ad4 100644
--- a/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsx
+++ b/apps/studio/components/ui/AIAssistantPanel/MessageMarkdown.tsx
@@ -38,8 +38,19 @@ const Streamdown = dynamic<StreamdownProps>(
{ ssr: false }
)
-export const OrderedList = memo(({ children }: { children?: ReactNode }) => (
- <ol className="flex flex-col gap-y-4">{children}</ol>
+// Streamdown splits ordered lists with complex content (e.g. code blocks) into
+// separate <ol> elements. The `start` attribute preserves semantics for screen
+// readers, while `counterReset` is what actually fixes the visible numbering —
+// the prose config (tailwind.config.js) uses a custom CSS counter named "item"
+// with `listStyleType: 'none'`, so the `start` attribute alone has no visual effect.
+export const OrderedList = memo(({ children, start }: { children?: ReactNode; start?: number }) => (
+ <ol
+ className="flex flex-col gap-y-4"
+ start={start}
+ style={start !== undefined ? { counterReset: `item ${start - 1}` } : undefined}
+ >
+ {children}
+ </ol>
))
OrderedList.displayName = 'OrderedList'