-
Notifications
You must be signed in to change notification settings - Fork 58
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
CPLAT-3616 Warn consumers about props / state mutation #249
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one tiny #nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+10
@@ -444,6 +444,18 @@ abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiStat | |||
// ---------------------------------------------------------------------- | |||
} | |||
|
|||
class WarnOnModify<K, V> extends MapView<K, V> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be private (add an underscore to the beginning of the name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nits
Co-Authored-By: joebingham-wk <46691367+joebingham-wk@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
+1, will merge pending travis build |
+10 @Workiva/release-management-pp |
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.