8000 fix(sdk): Remove ExplicitSize findDOMNode console errors by oisincoveney · Pull Request #52253 · metabase/metabase · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): Remove ExplicitSize findDOMNode console errors #52253

Merged
merged 10 commits into from
Jan 30, 2025

Conversation

oisincoveney
Copy link
Contributor
@oisincoveney oisincoveney commented Jan 16, 2025

Removes console.error about findDOMNode being deprecated by removing findDOMNode from ExplicitSize.

findDOMNode is a way for react to get the root HTML element of the component that's passed into that function, so findDOMNode(this) gets the root element of the component in which it's called. To refactor this, we have to create a ref and explicitly pass that into the components that use this HOC.

Nothing should change. findDOMNode error messages for ExplicitSize should be gone now. Manual testing is the way to go for now I think

ExplicitSize is used in the following files, we need to explicitly pass a ref in these components to replace this functionality.

  • frontend/src/metabase/components/DebouncedFrame/DebouncedFrame.jsx:119
  • frontend/src/metabase/components/FieldValuesWidget/FieldValuesWidget.tsx:523
  • frontend/src/metabase/core/components/TabRow/TabRow.tsx:136
  • frontend/src/metabase/dashboard/components/DashboardGrid.tsx:690
  • frontend/src/metabase/query_builder/components/NativeQueryEditor/AceEditor/AceEditor.tsx:552
  • frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx:455
  • frontend/src/metabase/query_builder/components/expressions/ExpressionEditorTextfield/ExpressionEditorTextfield.tsx:842
  • frontend/src/metabase/query_builder/components/view/View/View/View.jsx:293
  • frontend/src/metabase/visualizations/components/CardRenderer.jsx:81
  • frontend/src/metabase/visualizations/components/ChartWithLegend.jsx:157
  • frontend/src/metabase/visualizations/components/TableInteractive/TableInteractive.jsx:1365
  • frontend/src/metabase/visualizations/components/TableSimple/TableSimple.tsx:260
  • frontend/src/metabase/visualizations/components/Visualization/Visualization.jsx:555
  • frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.tsx:545

Some other files have been updated with forwardRef since we pass refs explicitly now to satisfy the fact that we need explicit refs to replace findDOMNode

@oisincoveney
Copy link
Contributor Author
oisincoveney commented Jan 16, 2025

This change is part of the following stack:

Change managed by git-spice.

Copy link
trunk-io bot commented Jan 16, 2025

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Copy link
Contributor
github-actions bot commented Jan 16, 2025

Codenotify: Notifying subscribers in CODENOTIFY files for diff 6f02407...eb2e3f5.

Notify File(s)
@alxnddr frontend/src/metabase/visualizations/components/CardRenderer.jsx
frontend/src/metabase/visualizations/components/ChartWithLegend.jsx
frontend/src/metabase/visualizations/components/TableInteractive/TableInteractive.jsx
frontend/src/metabase/visualizations/components/TableSimple/TableSimple.tsx
frontend/src/metabase/visualizations/components/Visualization/Visualization.jsx
frontend/src/metabase/visualizations/visualizations/PivotTable/PivotTable.tsx

@oisincoveney oisincoveney added backport Automatically create PR on current release branch on merge Embedding/SDK Embedding SDK for React labels Jan 21, 2025
@oisincoveney oisincoveney changed the base branch from master to ts-conversion/loading-error-wrapper January 22, 2025 02:22
@oisincoveney oisincoveney requested a review from a team as a code owner January 22, 2025 02:22
@oisincoveney oisincoveney force-pushed the sdk/remove-find-dom-node-from-explicit-size branch 4 times, most recently from bc8df3b to ddce178 Compare January 22, 2025 19:55
@oisincoveney oisincoveney force-pushed the ts-conversion/loading-error-wrapper branch from c16cdc2 to 74f81b7 Compare January 22, 2025 23:29
@oisincoveney oisincoveney force-pushed the sdk/remove-find-dom-node-from-explicit-size branch 2 times, most recently from 3b6a883 to 51072de Compare January 23, 2025 21:55
@oisincoveney oisincoveney requested review from a team as code owners January 23, 2025 21:55
@oisincoveney oisincoveney force-pushed the sdk/remove-find-dom-node-from-explicit-size branch 2 times, most recently from b884898 to 474fc29 Compare January 23, 2025 22:08
@oisincoveney oisincoveney removed request for a team January 23, 2025 22:09
Base automatically changed from ts-conversion/loading-error-wrapper to master January 24, 2025 15:37
@oisincoveney oisincoveney force-pushed the sdk/remove-find-dom-node-from-explicit-size branch from c608634 to 4377ea8 Compare January 24, 2025 15:51
@oisincoveney oisincoveney requested a review from a team January 24, 2025 15:52
@oisincoveney oisincoveney force-pushed the sdk/remove-find-dom-node-from-explicit-size branch from 4377ea8 to ea9e992 Compare January 24, 2025 15:54
@oisincoveney oisincoveney changed the title Start looking for all instances of ExplicitSize findDOMNode fix(sdk) Remove ExplicitSize findDOMNode Jan 24, 2025
@oisincoveney oisincoveney changed the title fix(sdk) Remove ExplicitSize findDOMNode fix(sdk): Remove ExplicitSize findDOMNode console errors Jan 24, 2025
@oisincoveney oisincoveney force-pushed the sdk/remove-find-dom-node-from-explicit-size branch from 39493e8 to 9463545 Compare January 27, 2025 20:04
@WiNloSt WiNloSt self-requested a review January 28, 2025 12:34
@@ -451,6 +457,7 @@ export function FieldValuesWidgetInner({
minWidth: minWidth ?? undefined,
maxWidth: maxWidth ?? undefined,
}}
ref={ref}
Copy link
Member

Choose a reason for hiding this comment

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

I guess this would behave differently when the error message is shown, since getDomNode should return the error node, but in the real world, I don't know how much difference that would make. Can you just ensure the UI behavior are the same even when this component throw errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it made much of a difference but just for completeness I've added a forwardRef to ErrorBoundary and made the corresponding changes. I think it's better that we have these explicitly passed (I mean... we have to if we want to get away from this error)

"data-testid": testId,
children,
}: LoadingAndErrorWrapperProps) => {
export const LoadingAndErrorWrapper = forwardRef<
Copy link
Member

Choose a reason for hiding this comment

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

some of the files here aren't listed as the component that uses ExplicitSize, I assume these component are the top level component used in a component that uses ExplicitSize? That way we need to pass ref to the underlying component and we need to forward refs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, that's exactly it. I should have mentioned that - when I didn't use forwardRef on here, we would get even more console errors which would defeat the purpose of this PR

children?: ReactNode;
}

const TabList = forwardRef(function TabGroup<T>(
{ value, onChange, onScroll, children, ...props }: TabListProps<T>,
{ value, onChange, onScroll, children, rootRef, ...props }: TabListProps<T>,
Copy link
Member

Choose a reason for hiding this comment

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

can't we wrap ref again like in other components, so we don't need an extra ref prop? I'm worried this will be hard to understand over time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me see if I can do something about this. I hated this solution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so apparently we can merge the tabListRef with the current ref and we should be ok. It looks like TabListRoot and TabListContent keep the same width

<TabList
onChange={onChange as (value: unknown) => void}
onScroll={event => setScrollPosition(event.currentTarget.scrollLeft)}
rootRef={ref}
Copy link
Member

Choose a reason for hiding this comment

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

I think I already commented about this. What about we wrap ref instead of passing an additional ref prop? I find this inconsistent with other wrapped ref and the API isn't super clear.

@@ -1137,7 +1137,9 @@ class TableInteractive extends Component {
} = this.props;

if (!width || !height) {
return <div className={className} />;
return (
<div ref={el => this.props.forwardedRef(el)} className={className} />
Copy link
Member

Choose a reason for hiding this comment

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

why can't we just simply pass ref?

Suggested change
<div ref={el => this.props.forwardedRef(el)} className={className} />
<div ref={this.props.forwardedRef} className={className} />

return (
<TableInteractiveRoot
ref={el => this.props.forwardedRef?.(el)}
Copy link
Member

Choose a reason for hiding this comment

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

same as the previous comment

Comment on lines +555 to +557
const VisualizationMemoized = memoizeClass("_getQuestionForCardCached")(
Visualization,
);
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to extract a component here? Can't we keep the HoC in the same _.compose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was having trouble getting this to work because I kept running into a few errors that had to do with the memoizeClass function and for the life of me could not get it to work. I'm going to try something else but I'd prefer it to work

Copy link
Member

Choose a reason for hiding this comment

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

I think it'd have something to do with the order you define HoCs. It should be possible to put this in connect and behave the same.

@WiNloSt WiNloSt dismissed their stale review January 28, 2025 13:10

The requested change has been made.

@WiNloSt WiNloSt requested a review from a team January 28, 2025 13:10
@oisincoveney oisincoveney requested a review from a team January 29, 2025 22:26
@oisincoveney oisincoveney merged commit 70d4582 into master Jan 30, 2025
138 checks passed
@oisincoveney oisincoveney deleted the sdk/remove-find-dom-node-from-explicit-size branch January 30, 2025 20:39
@oisincoveney
Copy link
Contributor Author

@metabase-bot backport release-x.52.x

Copy link
Contributor

@oisincoveney Manual conflict resolution is required

oisincoveney added a commit that referenced this pull request Feb 4, 2025
@github-actions github-actions bot added this to the 0.52.10 milestone Feb 4, 2025
oisincoveney added a commit that referenced this pull request Feb 6, 2025
Copy link
Contributor
github-actions bot commented Feb 6, 2025

🚀 This should also be released by v0.53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge Embedding/SDK Embedding SDK for React .Team/Embedding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0