figma-plugin-react-template
figma-plugin-react-template copied to clipboard
onmessage on App.tsx won't fire if plugin is closed immediately
This tripped me up for a while until I realized why the onmessage in App.tsx doesn't fire in the example. Maybe just add a setTimeout to the figma.closePlugin call in controller.ts along with a comment.
Hey @butteredcorn, I'd be happy to get a PR fixing this 🙏🏼
I don't think the state is being updated inside the onmessage callback. The setIsLoading(false) isn't working, yet there is output in the console.
useEffect(() => {
const messageHandler = (event) => {
const { type, data } = event.data.pluginMessage;
switch (type) {
case FromPlugin.SETTINGS_LOADED:
case FromPlugin.SETTINGS_SAVED:
console.log('DATA', data);
setIsLoading(false);
console.log('FALSE');
break;
}
};
window.addEventListener('message', messageHandler.bind(this));
return () => {
window.removeEventListener('message', messageHandler);
};
}, []);