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

Replace defaultProps with destructuring in function components #7145

Merged
merged 8 commits into from
Jan 12, 2025

Conversation

ggdouglas
Copy link
Contributor

@ggdouglas ggdouglas commented Jan 9, 2025

Copied from React 18 Upgrade feature branch #7142

Proposed changes:

Replaces defaultProps with destructuring in anticipation of lint errors that will be encountered in React 18.3.0.

Fixes lint errors such as the following:

error: 'defaultProps' is deprecated. Use {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#default_valuedefault values for destructuring assignments instead} (deprecation/deprecation) at src/components/card-list/cardList.tsx:61:10:
         59 |     );
         60 | });
       > 61 | CardList.defaultProps = {
            |          ^
         62 |     bordered: true,
         63 |     compact: false,
         64 | };

See also:

@ggdouglas ggdouglas mentioned this pull request Jan 9, 2025
15 tasks
@palantir palantir deleted a comment from changelog-app bot Jan 9, 2025
@svc-palantir-github
Copy link

Replace `defaultProps` with destructuring in function components

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@svc-palantir-github
Copy link

Revert defaultProps changes to DateInput3 to fix tests

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Copy link
Contributor

@gluxon gluxon left a comment

Choose a reason for hiding this comment

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

Thanks! Scrolled through and I believe we've properly copied the defaults over. Only question is around whether we should share default values through an export somehow.

@@ -146,7 +146,7 @@ export class Dialog extends AbstractPureComponent<DialogProps> {
<div
className={classNames(Classes.DIALOG, className)}
role={role}
aria-modal={overlayProps.enforceFocus ?? Overlay2.defaultProps?.enforceFocus}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be useful to have Overlay2 still export its default props if we need to reference them internally?

// Overlay2.tsx

export const OVERLAY2_DEFAULT_PROPS = {
  enforceFocus: true
};

I think that makes it easier to see the intent of the code here. Otherwise it's more difficult to know why someone chose to default aria-modal to true.

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, can do! I 👍 had considered something like this originally, but wavered at the time of implementing. I think this is a good idea for posterity since these can technically be consumed externally. Having the export set of values to point to will give us a migration path in case there are any other consumers we are unaware of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -660,7 +660,7 @@ describe("<DateInput>", () => {
focusInput(wrapper);
changeInput(wrapper, "4/77/2016");
blurInput(wrapper);
assert.strictEqual(wrapper.find(InputGroup).prop("value"), DateInput.defaultProps?.invalidDateMessage);
assert.strictEqual(wrapper.find(InputGroup).prop("value"), "Invalid date");
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment around potentially exporting default props from DateInput.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +572 to +573
// TODO: Removing `defaultProps` here breaks tests. Investigate why.
// eslint-disable-next-line deprecation/deprecation
Copy link
Contributor

Choose a reason for hiding this comment

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

That's fun. 😂

Thanks for leaving a comment so others have context on this in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah.. 🥲

I am working on updating/refactoring a lot of the datetime2 tests currently, so will hopefully uncover the cause of this during the process.

@ggdouglas ggdouglas requested a review from gluxon January 10, 2025 19:21
@svc-palantir-github
Copy link

Leverage inferred type for backdropProps to fix type error

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

This test passes locally but fails in CI. Need to investigate why this occurs.

```
Chrome Headless 124.0.6367.201 (Linux x86_64) <Popover> focus management when shouldReturnFocusOnClose={true} moves focus to overlay when opened FAILED
        Error: Uncaught focus should be inside overlay: expected null to not equal null
        ...
```
@svc-palantir-github
Copy link

Revert default assignments in Overlay2 props to avoid test flake in CI

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

gluxon
gluxon previously approved these changes Jan 10, 2025
packages/select/src/components/suggest/suggest.tsx Outdated Show resolved Hide resolved
@policy-bot policy-bot bot dismissed gluxon’s stale review January 11, 2025 01:43

Invalidated by push of aefacb1

@svc-palantir-github
Copy link

Revert change to replace Popover default props reference in Suggest

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

@ggdouglas ggdouglas merged commit 0a63583 into develop Jan 12, 2025
12 of 17 checks passed
@ggdouglas ggdouglas deleted the feat/react-18-deprecated-defaultProps branch January 12, 2025 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants