Skip to content

Commit a9123f3

Browse files
fix(editor): keep bubble menu styles in production builds (#3905)
1 parent 1c0a117 commit a9123f3

5 files changed

Lines changed: 36 additions & 13 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/editor": patch
3+
---
4+
5+
Fix the bubble menu losing its layout and theme in Next.js 16.4 production builds with Turbopack. The `data-re-bubble-menu` attribute, `className` and `style` now go on an inner element, not on TipTap's positioned element.

‎apps/web/src/components/sections/editor.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const EditorHomepage = () => {
5151
<div className="md:w-4/6 bg-white md:aspect-video z-20 relative border border-slate-4 grow rounded-2xl sm:rounded-3xl overflow-hidden [overflow-anchor:none] -order-1 md:order-0 flex flex-col">
5252
<EmailEditor
5353
content={INITIAL_CONTENT}
54-
className="flex-1 overflow-auto px-6 w-full [&>div]:w-full [&_div]:outline-none"
54+
className="flex-1 overflow-auto px-6 w-full [&>.tiptap]:w-full [&_div]:outline-none"
5555
onReady={async (editor) => {
5656
const html = await editor.getEmailHTML();
5757
setHtml(html);

‎packages/editor/src/ui/bubble-menu/bubble-menu.css‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
[data-re-bubble-menu] {
7+
position: relative;
78
display: flex;
89
align-items: center;
910
gap: 0.125rem;

‎packages/editor/src/ui/bubble-menu/root.spec.tsx‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@ import { BubbleMenuRoot } from './root';
77
vi.mock('@tiptap/react/menus', () => ({
88
BubbleMenu: ({
99
children,
10-
className,
1110
options,
1211
ref,
13-
}: {
12+
editor: _editor,
13+
pluginKey: _pluginKey,
14+
shouldShow: _shouldShow,
15+
...rest
16+
}: React.HTMLAttributes<HTMLDivElement> & {
1417
children: React.ReactNode;
15-
className?: string;
1618
options?: { placement?: string; offset?: number; onHide?: () => void };
1719
ref?: React.Ref<HTMLDivElement>;
20+
editor?: unknown;
21+
pluginKey?: unknown;
22+
shouldShow?: unknown;
1823
}) => (
1924
<div
25+
{...rest}
2026
ref={ref}
2127
data-testid="bubble-menu-root"
22-
data-re-bubble-menu=""
2328
data-placement={options?.placement}
2429
data-offset={options?.offset}
25-
className={className}
2630
>
2731
{children}
2832
</div>
@@ -148,11 +152,24 @@ describe('BubbleMenuRoot', () => {
148152
expect(root.dataset.offset).toBe('16');
149153
});
150154

151-
it('forwards className to the BubbleMenu', () => {
152-
renderWithEditor(<BubbleMenuRoot className="custom-class" />);
155+
it('renders className, style and attributes on its own menu element', () => {
156+
renderWithEditor(
157+
<BubbleMenuRoot
158+
className="custom-class"
159+
style={{ color: 'red' }}
160+
aria-label="Formatting"
161+
/>,
162+
);
153163

154164
const root = screen.getByTestId('bubble-menu-root');
155-
expect(root.className).toBe('custom-class');
165+
const menu = root.firstElementChild as HTMLElement;
166+
expect(menu.hasAttribute('data-re-bubble-menu')).toBe(true);
167+
expect(menu.className).toBe('custom-class');
168+
expect(menu.style.color).toBe('red');
169+
expect(menu.getAttribute('aria-label')).toBe('Formatting');
170+
expect(root.hasAttribute('data-re-bubble-menu')).toBe(false);
171+
expect(root.className).toBe('');
172+
expect(root.style.color).toBe('');
156173
});
157174
});
158175
});

‎packages/editor/src/ui/bubble-menu/root.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ function Root({
5959
<BubbleMenu
6060
editor={editor}
6161
pluginKey={pluginKey}
62-
data-re-bubble-menu=""
6362
shouldShow={resolvedTrigger}
6463
options={{
6564
placement,
@@ -69,11 +68,12 @@ function Root({
6968
onHide?.();
7069
},
7170
}}
72-
className={className}
73-
{...rest}
7471
>
7572
<BubbleMenuContext.Provider value={{ editor, isEditing, setIsEditing }}>
76-
{children}
73+
{/* React sets these props, because Turbopack before Next.js 16.5 drops TipTap's attribute and style sync. */}
74+
<div data-re-bubble-menu="" className={className} {...rest}>
75+
{children}
76+
</div>
7777
</BubbleMenuContext.Provider>
7878
</BubbleMenu>
7979
</EditorFocusScope>

0 commit comments

Comments
 (0)