-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: prevent sending updated props to plugin when props do not change [LIBS-514] #1351
Conversation
|
||
const [inErrorState, setInErrorState] = useState<boolean>(false) | ||
|
||
// since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop | ||
const memoizedPropsToPass = useMemo( |
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 is the fix. I'm not sure I like this solution but since it's unknown what props are actually going to be passed, this was the best way I could come up with handling the dependency array.
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.
shouldn't the memoized value change if the values
of the propsToPass
change, not just the keys
? will that be the case now?
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.
🤦♂️ thanks @kabaros. Yes; this should have been [...Object.values(propsToPass)]
...but now I think I remember that I did that originally, but then thought that the order of the props wouldn't theoretically guaranteed to be in the same order on the object, hence it might be better to do something like [...Object.keys(propsToPass).sort().map(k=>propsToPass[k])]
, but then I get a type error:
No index signature with a parameter of type 'string' was found on type '{ propsToPass: PropsObject; }'.
And then I tried to explicitly declare propsToPass as an object with string keys (I made an interface of
interface PropsObject {
[propName: string]: any;
}
but that did not resolve the type issues 🫤
I've pushed a change to [...Object.keys(propsToPass).sort().map(k=>propsToPass[k])]
, but let me know if you have tips about what I could to fix the type warnings 🙏
🎉 This PR is included in version 3.10.0-alpha.7 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 3.11.0-alpha.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Implements LIBS-514
Key features
Fixes app/plugin communication to pass props via post-robot only when the props provided to wrapper component have changed.
Description
Noted on ticket, but the intent of the wrappers was only to send a communication update when props passed to the component changed. However, when the parent with component updated, the plugins were deemed to have changed because of unstable object references (even when the passed props were themselves stable)
e.g. we had an app that passed stabled references to the whenever it rerendered:
however, when in the Plugin wrapper component...
the overall props object was not itself a stable reference, hence while the individual values were not changing, the communication would reoccur.
Checklist