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

FED-1721 Null safety preparation for class component default props / initial state #284

Merged
merged 34 commits into from
Apr 23, 2024

Conversation

aaronlademann-wf
Copy link
Contributor

@aaronlademann-wf aaronlademann-wf commented Apr 10, 2024

Motivation

Class based components use defaultProps and initialState to set the value of certain props / state fields when the class is constructed.

To map this pattern to null safety - we need props that are defaulted, and state that is initialized to be marked with a /*late*/ hint to indicate that it will be set at the time of class construction, and a /*!*/ hint to assist the null safety migrator so it knows that defaulted props / initialized state will never be null.

Changes

  1. Add two suggestor classes that share a lot of common functionality in order to add the aforementioned hints on prop field declarations that are defaulted, and on state field declarations that are initialized.
  2. Add those suggestors to the existing null_safety_migrator_companion executable.
  3. Write tests.

What it does

Before

mixin FooProps on UiProps {
  String defaultedNullable;
  num defaultedNonNullable;
}
mixin FooState on UiState {
  String initializedNullable;
  bool initializedNonNullable;
}
class FooComponent extends UiStatefulComponent2<FooProps, FooState> {
  @override
  get defaultProps => (newProps()
    ..defaultedNullable = null
    ..defaultedNonNullable = 2.1
  );

  @override
  get initialState => (newState()
    ..initializedNullable = null
    ..initializedNonNullable = true
  );
  // ...
}

After

mixin FooProps on UiProps {
  /*late*/ String/*?*/ defaultedNullable;
  /*late*/ num/*!*/ defaultedNonNullable;
}
mixin FooState on UiState {
  /*late*/ String/*?*/ initializedNullable;
  /*late*/ bool/*!*/ initializedNonNullable;
}
class FooComponent extends UiStatefulComponent2<FooProps, FooState> {
  @override
  get defaultProps => (newProps()
    ..defaultedNullable = null
    ..defaultedNonNullable = 2.1
  );

  @override
  get initialState => (newState()
    ..initializedNullable = null
    ..initializedNonNullable = true
  );
  // ...
}

Release Notes

Review

See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.

Please review:

QA Checklist

  • Tests were updated and provide good coverage of the changeset and other affected code
  • Manual testing was performed if needed

Merge Checklist

While we perform many automated checks before auto-merging, some manual checks are needed:

  • A Frontend Frameworks Design member has reviewed these changes
  • There are no unaddressed comments - this check can be automated if reviewers use the "Request Changes" feature
  • For release PRs - Version metadata in Rosie comment is correct

that is essentially identical to the defaultProps one
@aviary2-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

Made some comments, but they're mostly minor. This looks awesome!

…ED-1721_class-component-default-props
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

+1, gonna take a break then do some QAing!

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

Just a couple things found while QAing. Tested on a few repos and the output looks fantastic!

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

+10

@Workiva/release-management-p

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

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

+1 from RM

@rmconsole7-wk rmconsole7-wk merged commit 3d427d5 into master Apr 23, 2024
6 checks passed
@rmconsole7-wk rmconsole7-wk deleted the FED-1721_class-component-default-props branch April 23, 2024 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants