Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
tooltips,
} from '@codemirror/view';
import { classHighlighter } from '@lezer/highlight';
import { useRef } from 'react';
import { useState } from 'react';

import { GlobalConstants, isObjectsEqual } from '@cloudbeaver/core-utils';
import { clsx } from '@dbeaver/ui-kit';
Expand Down Expand Up @@ -119,16 +119,18 @@ const DEFAULT_EXTENSIONS_COMPARTMENT = new Compartment();

/** Provides the necessary extensions to establish a basic editor */
export function useEditorDefaultExtensions(options?: IDefaultExtensions): [Compartment, Extension] {
const previousOptions = useRef(options);
const isOptionsChanged = !isObjectsEqual(options, previousOptions.current);
const extensions = useRef<[Compartment, Extension] | null>(null);
const [state, setState] = useState<{ options: IDefaultExtensions | undefined; result: [Compartment, Extension] }>(() => ({
options,
result: createExtensions(options),
}));

if (isOptionsChanged || extensions.current === null) {
previousOptions.current = options;
extensions.current = createExtensions(options);
if (!isObjectsEqual(options, state.options)) {
const result = createExtensions(options);
setState({ options, result });

@devnaumov devnaumov Jun 4, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will cause extra rerenders, its better to comment such code parts as expected than fix it this way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how many? how will it affect the product?

@devnaumov devnaumov Jun 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Props are changed -> rerender, then if options are different, you are setting state that rerenders one more time and its just a bad react practice. You are executing state update from component body to sync state from props, it might cause infinite rerenders and other problems. I think that the prev approach is cleaner and less buggy. If we know what we are doing, we dont need to fix it. I suggest to disable this eslint rule as this pattern is commonly used across react ecosystem, what do you think?

return result;
}

return extensions.current;
return state.result;
}

function createExtensions(options?: IDefaultExtensions): [Compartment, Extension] {
Expand Down
Loading