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

onmessage on App.tsx won't fire if plugin is closed immediately #35

Open
butteredcorn opened this issue Feb 12, 2023 · 2 comments
Open

Comments

@butteredcorn
Copy link

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.

@nirsky
Copy link
Owner

nirsky commented Apr 19, 2023

Hey @butteredcorn, I'd be happy to get a PR fixing this 🙏🏼

@usman-careem
Copy link

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);
    };
  }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants