Skip to content

Commit 2ccd8b7

Browse files
committed
chore(query-bar): better fix for codemirror placeholder issue
1 parent e5d4079 commit 2ccd8b7

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

packages/compass-generative-ai/src/components/ai-experience-entry.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function createAIPlaceholderHTMLPlaceholder({
135135
darkMode?: boolean;
136136
placeholderText: string;
137137
track: TrackFunction;
138-
}): HTMLElement {
138+
}): () => HTMLElement {
139139
const containerEl = document.createElement('div');
140140

141141
const placeholderTextEl = document.createTextNode(`${placeholderText} or `);
@@ -171,17 +171,9 @@ ${getAIEntrySVGString()}`;
171171

172172
containerEl.appendChild(aiButtonEl);
173173

174-
// Workarond for https://github.com/codemirror/dev/issues/1519: codemirror
175-
// will try to `cloneNode` the placeholder (for somewhat good reasons) which
176-
// doesn't carry over the events we attach. There's no way to opt-out of this
177-
// behavior, so we're just overriding cloneNode function to stop this from
178-
// happening. This is covered by tests, so in case it stops working, we will
179-
// know
180-
containerEl.cloneNode = () => {
181-
return containerEl;
182-
};
183-
184-
return containerEl;
174+
// Return a function to prevent codemirror from cloning the DOM node (this
175+
// doesn't transfer event listeners)
176+
return () => containerEl;
185177
}
186178

187179
export { AIExperienceEntry, createAIPlaceholderHTMLPlaceholder };

packages/compass-query-bar/src/components/option-editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type OptionEditorProps = {
8888
onChange: (value: string) => void;
8989
onApply?(): void;
9090
onBlur?(): void;
91-
placeholder?: string | HTMLElement;
91+
placeholder?: string | (() => HTMLElement);
9292
serverVersion?: string;
9393
value?: string;
9494
['data-testid']?: string;

packages/compass-query-bar/src/components/query-option.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type QueryOptionProps = {
8787
value?: string;
8888
hasError: boolean;
8989
onChange: (name: QueryBarProperty, value: string) => void;
90-
placeholder?: string | HTMLElement;
90+
placeholder?: string | (() => HTMLElement);
9191
onApply?(): void;
9292
disabled?: boolean;
9393
};

0 commit comments

Comments
 (0)