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

CPLAT-3616 Warn consumers about props / state mutation #249

Merged

Conversation

joebingham-wk
Copy link
Contributor

@joebingham-wk joebingham-wk commented Feb 18, 2019

Ultimate problem:

With the upcoming change to the component_base class, setting the state / props directly will cause breakages. To give consumers a heads up, we should emit warnings in the browser console when they directly mutate props / state values inside a component instance.

How it was fixed:

Adding a class called WarnOnUpdate that watches for setting props / state directly and throws an error in dev mode using an Assert.

Testing suggestions:

Run the test suite. Consider any ways the tests could return false results or miss a use case.

Potential areas of regression:

None that are known as it's only in dev that the error will be thrown.

@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

@kealjones-wk kealjones-wk left a comment

Choose a reason for hiding this comment

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

one tiny #nit

Copy link
Contributor

@kealjones-wk kealjones-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

@aaronlademann-wf aaronlademann-wf changed the title Cplat 3616 props mutation warning CPLAT-3616 Warn consumers about props / state mutation Feb 19, 2019
lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
@@ -444,6 +444,18 @@ abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiStat
// ----------------------------------------------------------------------
}

class WarnOnModify<K, V> extends MapView<K, V> {
Copy link
Contributor

Choose a reason for hiding this comment

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

lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
Copy link
Contributor

@kealjones-wk kealjones-wk left a comment

Choose a reason for hiding this comment

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

Just some nits

lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
lib/src/component_declaration/component_base.dart Outdated Show resolved Hide resolved
kealjones-wk and others added 2 commits February 20, 2019 13:25
Co-Authored-By: joebingham-wk <46691367+joebingham-wk@users.noreply.github.com>
Copy link
Contributor

@kealjones-wk kealjones-wk left a comment

Choose a reason for hiding this comment

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

+1

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.

+1

QA +10

if (isProps) {
message =
'''
props["$key"] was updated incorrectly. Never mutate this.props directly, as it can cause unexpected behavior;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this currently print out to the console all indented? If so, we should wrap it in an unindent.

@greglittlefield-wf
Copy link
Contributor

+1, will merge pending travis build

@greglittlefield-wf
Copy link
Contributor

+10

@Workiva/release-management-pp

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.

7 participants