Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Let RichTextProvider change its placeholder after mount

Rafi7f771553f92e
diff --git a/packages/ui/src/rich-text-area/rich-text-provider.tsx b/packages/ui/src/rich-text-area/rich-text-provider.tsx
index 87edc9f8a2..38e48e85e0 100644
--- a/packages/ui/src/rich-text-area/rich-text-provider.tsx
+++ b/packages/ui/src/rich-text-area/rich-text-provider.tsx
@@ -163,6 +163,10 @@ export const RichTextProvider = forwardRef<
// Ref to avoid stale closures in editorProps handlers below
const editorRef = useRef<Editor | null>(null);
+ // Read through a ref so the placeholder can change after the editor is created
+ const placeholderRef = useRef(placeholder);
+ placeholderRef.current = placeholder;
+
const openLinkModal = useCallback((pos?: number) => {
const editor = editorRef.current;
if (!editor) return;
@@ -254,7 +258,7 @@ export const RichTextProvider = forwardRef<
: []),
Placeholder.configure({
- placeholder,
+ placeholder: () => placeholderRef.current,
emptyEditorClass:
"before:content-[attr(data-placeholder)] before:float-left before:text-content-muted before:h-0 before:pointer-events-none",
}),
@@ -441,6 +445,12 @@ export const RichTextProvider = forwardRef<
editor?.setEditable(editable ?? true);
}, [editor, editable]);
+ // An empty transaction redraws the placeholder decoration
+ useEffect(() => {
+ if (!editor || editor.isDestroyed) return;
+ editor.view.dispatch(editor.state.tr);
+ }, [editor, placeholder]);
+
useImperativeHandle(ref, () => ({
setContent: (content: any) => {
editor?.commands.setContent(content);