Skip to content

Commit 9c10943

Browse files
authored
fix(content): stop wide markdown tables breaking the mobile layout (#5984)
* fix(content): stop wide markdown tables breaking the mobile layout Library and blog posts render GFM tables straight into the prose container with no width bound. Comparison tables run up to nine columns, so on a phone the table set the article's content width and body copy was clipped at both edges with no way to scroll to it — the table simply ran off the canvas. 19 of 20 library posts contain a table. Wraps tables in an `overflow-x-auto` container so that scrolling is confined to the table's own axis, and gives the table a `min-w` so columns do not crush to one word per line inside it. Both surfaces share `mdxComponents`, so this covers blog posts too. Also adds `lib/**` to Tailwind's content globs. `lib/content/mdx.tsx` emits classes like any component, but only `app`, `components`, and `pages` were scanned, so a class unique to that file was silently never generated — `min-w-[520px]` here, and already `list-outside`, `text-[19px]`, and `text-[0.9em]` on the existing paragraph and list styles. Verified against a real browser: without the glob the rule is absent and computed `min-width` stays `0px`. Generated CSS grows 538 bytes minified (+0.26%), all additions, nothing removed. * chore(content): type the table renderer instead of any Uses `ComponentPropsWithoutRef<'table'>` so the destructured and forwarded props are checked. The surrounding renderers in this file still take `any`; converting them is a separate cleanup, not something to fold into a mobile layout fix.
1 parent 66ac015 commit 9c10943

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

apps/sim/lib/content/mdx.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ComponentPropsWithoutRef } from 'react'
12
import clsx from 'clsx'
23
import type { MDXRemoteProps } from 'next-mdx-remote/rsc'
34
import { CodeBlock } from '@/lib/content/code'
@@ -122,6 +123,21 @@ export const mdxComponents: MDXRemoteProps['components'] = {
122123
/>
123124
)
124125
},
126+
/**
127+
* GFM comparison tables run up to nine columns of prose, which no phone can
128+
* fit. Without a scroll container the table sets the page's content width and
129+
* the whole article scrolls sideways, clipping body copy at both edges. The
130+
* wrapper confines that scrolling to the table's own axis.
131+
*
132+
* `min-w` keeps columns from collapsing to one word per line inside the
133+
* scroll area — narrow enough that tables which already fit (two or three
134+
* columns on a tablet, anything on desktop) never gain a scrollbar.
135+
*/
136+
table: ({ className, ...props }: ComponentPropsWithoutRef<'table'>) => (
137+
<div className='my-6 w-full overflow-x-auto'>
138+
<table {...props} className={clsx('my-0 min-w-[520px]', className)} />
139+
</div>
140+
),
125141
figure: (props: any) => (
126142
<figure {...props} className={clsx('my-8 overflow-hidden rounded-lg', props.className)} />
127143
),

apps/sim/tailwind.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ export default {
1313
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
1414
'./components/**/*.{js,ts,jsx,tsx,mdx}',
1515
'./app/**/*.{js,ts,jsx,tsx,mdx}',
16+
/**
17+
* `lib/content/mdx.tsx` styles rendered blog/library markdown, so it emits
18+
* classes like any component does. Without this glob Tailwind only
19+
* generates the ones that happen to appear in a scanned file too, and a
20+
* class unique to this directory silently resolves to nothing.
21+
*/
22+
'./lib/**/*.{js,ts,jsx,tsx,mdx}',
1623
'../../packages/emcn/src/**/*.{js,ts,jsx,tsx}',
1724
'../../packages/workflow-renderer/src/**/*.{js,ts,jsx,tsx}',
1825
'!./app/node_modules/**',

0 commit comments

Comments
 (0)