From 2efc64135ea1f588d2c7f90c5e03a96f0561a99e Mon Sep 17 00:00:00 2001 From: Claude Code Date: Tue, 12 May 2026 15:55:57 -0700 Subject: [PATCH] fix(lint,test): unblock CI on chore/fc-10-explore-sqllab-misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two failures from the latest commits on this branch: 1. oxlint no-use-before-define on DatasourceEditor.tsx — the isEditModeRef / onQueryFormatRef declarations sat after the componentDidMount useEffect that closes over them. JavaScript closes over the names at call time so it ran fine, but oxlint reads top-down and flags the order. Move the ref declarations and their sync useEffect ahead of the componentDidMount effect; lint clean and behavior identical. 2. CopyToClipboard.test.tsx used userEvent.keyboard('{enter}'), an API added in @testing-library/user-event v13.4. The pinned version in this repo is v12.8.3, so the call resolves to undefined and the test crashes with TypeError. Switch to fireEvent.keyDown(button, {key: 'Enter'}), which is v12-compatible and directly exercises the component's onKeyDown handler we're testing. Co-Authored-By: Claude Sonnet 4.6 --- .../CopyToClipboard/CopyToClipboard.test.tsx | 5 ++++- .../DatasourceEditor/DatasourceEditor.tsx | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/superset-frontend/src/components/CopyToClipboard/CopyToClipboard.test.tsx b/superset-frontend/src/components/CopyToClipboard/CopyToClipboard.test.tsx index 9feeb856416..700732675bf 100644 --- a/superset-frontend/src/components/CopyToClipboard/CopyToClipboard.test.tsx +++ b/superset-frontend/src/components/CopyToClipboard/CopyToClipboard.test.tsx @@ -17,6 +17,7 @@ * under the License. */ import { + fireEvent, render, screen, userEvent, @@ -59,7 +60,9 @@ test('non-element copyNode wrapper is keyboard-activatable', async () => { const button = screen.getByRole('button'); expect(button).toHaveAttribute('tabIndex', '0'); button.focus(); - await userEvent.keyboard('{enter}'); + // user-event v12 (pinned in this repo) doesn't expose .keyboard(); use + // fireEvent to dispatch the Enter keydown directly to the focused button. + fireEvent.keyDown(button, { key: 'Enter' }); await waitFor(() => expect(onCopyEnd).toHaveBeenCalled()); }); diff --git a/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx b/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx index f6b5169fcc6..f24ae3e3d28 100644 --- a/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx +++ b/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx @@ -1360,6 +1360,14 @@ function DatasourceEditor({ [], ); + // Keep the refs read by the (one-shot) Mousetrap handler up to date. + const isEditModeRef = useRef(isEditMode); + const onQueryFormatRef = useRef(onQueryFormat); + useEffect(() => { + isEditModeRef.current = isEditMode; + onQueryFormatRef.current = onQueryFormat; + }, [isEditMode, onQueryFormat]); + // componentDidMount useEffect(() => { isComponentMounted.current = true; @@ -1394,14 +1402,6 @@ function DatasourceEditor({ }; }, []); - // Keep the refs read by the (one-shot) Mousetrap handler up to date. - const isEditModeRef = useRef(isEditMode); - const onQueryFormatRef = useRef(onQueryFormat); - useEffect(() => { - isEditModeRef.current = isEditMode; - onQueryFormatRef.current = onQueryFormat; - }, [isEditMode, onQueryFormat]); - // componentDidUpdate for props.datasource changes // Only run when the props.datasource reference actually changes from parent useEffect(() => {