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-1978 Null-safe props documentation #916

Merged
merged 21 commits into from
May 15, 2024
Merged

FED-1978 Null-safe props documentation #916

merged 21 commits into from
May 15, 2024

Conversation

greglittlefield-wf
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf commented May 6, 2024

Motivation

We needed some documentation on required props and how they relate to null safety.

We also need to update code blocks in documentation to use null safety.

Changes

  • Small README cleanup
    • Make null safety the featured migration guide
    • Add basic docs around function components (can't believe we didn't have any 😓) #boyscouting
  • Add required props documentation
  • Update code blocks with null safety
    • In README
    • In doc comments

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

@aviary3-wk
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.

@@ -0,0 +1,411 @@
# Null safety and required props
Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub's "rich diff" viewer apparently doesn't render alerts very well, so I'd recommend viewing this file directly: https://github.com/Workiva/over_react/blob/null-safety-docs/doc/null_safety_and_required_props.md

@@ -243,11 +243,17 @@ The use-case for composing multiple props mixins into a single component props c

#### UiProps as a Map

> [!WARNING]
Copy link
Contributor Author

@greglittlefield-wf greglittlefield-wf May 6, 2024

Choose a reason for hiding this comment

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

GitHub's "rich diff" viewer apparently doesn't render alerts very well, so I'd recommend viewing this file directly: https://github.com/Workiva/over_react/blob/null-safety-docs/README.md#uiprops-as-a-map

Comment on lines -42 to -46
__There have been a lot of fantastic [improvements in this library recently](https://pub.dev/packages/over_react#-changelog-tab-)__, all of which require some action on your part if you have existing components built prior to the `3.1.0` release of OverReact. __We've done everything we can to make the migrations as painless as possible__ - with the vast majority of changes being handled by some codemod scripts you can run in your libraries locally. As always, if you encounter issues while working through the migration, you can reach out to us in [our gitter chat](https://gitter.im/over_react/Lobby), or [open a new issue][new-issue].

__First, you should upgrade your components to `UiComponent2`__. Check out the [`UiComponent2` Migration Guide](doc/ui_component2_transition.md) to learn about the benefits of `UiComponent2`, the codemod script you can run, and other updates you may need to make manually.

__Once you have migrated your components to `UiComponent2`__, you're ready to start using the "v3" component boilerplate - which is a _massive_ quality of life improvement for component authors! Check out the [Component Boilerplate Migration Guide](doc/new_boilerplate_migration.md) to learn about the benefits of the new boilerplate, the codemod script you can run, and other updates you may need to make manually.
Copy link
Contributor Author

@greglittlefield-wf greglittlefield-wf May 6, 2024

Choose a reason for hiding this comment

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

All this info (that's still relevant) is captured in the other migration guides

@greglittlefield-wf greglittlefield-wf changed the title Null-safe props documentation nFED-1885 Null-safe props documentation May 6, 2024
@greglittlefield-wf greglittlefield-wf changed the title nFED-1885 Null-safe props documentation FED-1885 Null-safe props documentation May 6, 2024
@greglittlefield-wf greglittlefield-wf marked this pull request as ready for review May 7, 2024 23:50
@aaronlademann-wf aaronlademann-wf changed the title FED-1885 Null-safe props documentation FED-1978 Null-safe props documentation May 8, 2024
Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a comment

Choose a reason for hiding this comment

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

This is great! Just found a couple of things...

README.md Outdated Show resolved Hide resolved
Comment on lines +873 to +874
bool? isDisabled;
Iterable<String>? items;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason these are nullable here, but not on line 817-818?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In those lines, they're props that are defaulted in a class component's defaultProps, whereas here, they're defaulted in a function component

doc/new_boilerplate_migration.md Show resolved Hide resolved
lib/src/component/hooks.dart Outdated Show resolved Hide resolved
Comment on lines 475 to 476
/// UiFactory<FancyInputProps> FancyInput = uiForwardRef(
/// (props, ref) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're using a ref declared in props instead of the forwarded ref, we probably should just make this uiFunction

Suggested change
/// UiFactory<FancyInputProps> FancyInput = uiForwardRef(
/// (props, ref) {
/// UiFactory<FancyInputProps> FancyInput = uiFunction(
/// (props) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the ref passed to a component isn't available in props.ref and so I believe you need to use forwardRef to use useImperativeHandle (see React docs here)

doc/null_safety_and_required_props.md Outdated Show resolved Hide resolved
doc/null_safety_and_required_props.md Outdated Show resolved Hide resolved
doc/null_safety_and_required_props.md Outdated Show resolved Hide resolved
doc/null_safety_and_required_props.md Outdated Show resolved Hide resolved
Copy link
Contributor

@sydneyjodon-wk sydneyjodon-wk left a comment

Choose a reason for hiding this comment

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

These docs are great!! Really clear and helpful! I just had some minor comments

doc/null_safety/null_safe_migration.md Outdated Show resolved Hide resolved
lib/src/component/hooks.dart Outdated Show resolved Hide resolved
doc/null_safety_and_required_props.md Show resolved Hide resolved
doc/null_safety_and_required_props.md Outdated Show resolved Hide resolved
Comment on lines +262 to +270
OverReact supports providing defaults for optional props in the following cases:

| Nullability | Class Component | Function component |
|--------------|-----------------|--------------------|
| Non-nullable | Yes<sup>1</sup> | No |
| Nullable | Yes | Yes<sup>2</sup> |

1. _Props are declared the same way required props are_
2. _Easiest when `null` is treated the same as the default_
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great explanation! I was expecting the following subsections to map to the three Yes boxes, but it seemed kind of unclear - could there be an example here (like maybe the last example - line 343) or links to the different sections or maybe rename the sections so it's really easy to find an example of each of these situations in the table?

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 took a stab and making this clearer, and also added a bit more content: d14ca46


### Defaulting nullable props using `??`

In over_react function components, prop defaulting for nullable props is typically implemented using null-aware `??` operators. As a result, unspecified props and explicit `null` values are treated the same.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also how you default nullable props in class components or is it only a function component thing? maybe the section headers could be updated depending on which is the case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a function component thing, but you can also do this in class components. I think I had originally written the header in a way to not exclude class components; I'll try updating this to be clearer

@greglittlefield-wf
Copy link
Contributor Author

Okay @aaronlademann-wf and @sydneyjodon-wk, I think I've addressed all your feedback!

Copy link
Contributor

@sydneyjodon-wk sydneyjodon-wk left a comment

Choose a reason for hiding this comment

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

+10 Looks great to me!!

Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a comment

Choose a reason for hiding this comment

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

@Workiva/release-management-pp

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

@rm-astro-wf rm-astro-wf merged commit 0200369 into master May 15, 2024
7 checks passed
@rm-astro-wf rm-astro-wf deleted the null-safety-docs branch May 15, 2024 18:20
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.

6 participants