React createRoot() not working in Modal

Hi,

I have previously posted about an issue with migrating from React 17 to React 18 and using createRoot() instead of the deprecated ReactDOM.render(). This is my previous post: App.initialized() not resolving under certain circumstances

This seems to have been resolved since then since I have now been able to upgrade to React 19 and the widget now properly renders in the ticket_sidebar.

However, with one of our widgets we utilize the showModal method (client.interface.trigger(‘showModal’, …) and it seems like the same problem exists here when trying to render the widget in the modal.

The appclient script gets attached to the DOM and loads, but when calling window.app.initialized() nothing happens, it doesn’t resolve and it doesn’t throw, it just stops executing. I have been able to confirm this by logging the steps to the console and I can see that execution just stops.

Going back to React 18 and using the deprecated ReactDOM.render() resolves the issue, but I would like to upgrade to React 19 and this bug is actively blocking me.

Is this a known issue and is there a fix planned?

Thanks in advance!

Hi @Wilnersson ,

we are working on introducing the upgraded react features in FDK, which will solve most of your cases, We will keep you posted, kindly stay tuned for the updates.

Thanks

1 Like

Hi @Santhosh ,

Thanks for the quick reply and the information, great to hear that you are working on it. Will hold off on the React upgrade for now then and get back to it at a later time.

All the best!

We released the new FDK 10.1.0, with new react framework, try to consume the same, it will solve most of your problems.

Thanks

Hello again Santhosh,

Thank you for the update. I tried upgrading in my dev-environment but unfortunately I am still seeing the same behaviour.

I have upgraded to FDK 10.1.0 and upgraded my project to React 19 as well as migrated to using createRoot() instead of ReactDOM.render().

This is the part of my App.js-file that is relevant:

  useLayoutEffect(() => {
    // To support StrictMode, if the script-element has already been mounted to the DOM, don't do it again.
    if (fwScriptElement.current !== null) return;
  
    const script = document.createElement('script');
    script.src = '{{{appclient}}}';
    script.defer = true;
    script.addEventListener('load', () => {
      console.log('Nestor DEV app-client script load event fired.');
      setLoaded(true);
    });
    document.head.appendChild(script);

    fwScriptElement.current = script;
  }, []);

  useLayoutEffect(() => {
    if (!loaded) return;
    console.log('Nestor DEV starting app initalization...');

    window.app.initialized().then((client) => {
      console.log('Nestor DEV app initialized!', client);

      getWidgetStartupMode(client).then((startupMode) => {
        if (!startupMode || !startupMode.module) {
          setChild((
            <FwInlineMessage open type='error'>
                Configuration error!
            </FwInlineMessage>
          ));
        }

        console.log('Nestor DEV app set to mode:', startupMode);
  
        setWidgetStartupMode(startupMode);
        setFwClient(client);
      });
    }).catch((err) => {
      console.error('Nestor DEV initialization error:', err);
    });

    return () => {
      setFwClient(null);
      setWidgetStartupMode(null);
    };
  }, [loaded]);

When I open the custom app in the sidebar everything works as expected and I can see the following in the console:
image
In other words, the script loads, the app initializes, I get my client and then it goes on loading the app.

But when I open the custom app in the modal, I only get this in the console:
image
So the loading of the script works fine, it enters the second useLayoutEffect() but when it is supposed to either go into the then() or catch()-blocks, execution stops and nothing more is logged. The app is then stuck in the loading state.

Hope this information helps!

Regards,
Henrik

Are you using the new React app? if not, try with fdk createreact-starter-template

and you can check the below example app, GitHub - freshworks-developers/superstack: Superstack is a Platform 3.0 Freshworks app showcasing React + FDK capabilities with production-ready examples, templates, and tooling to help you build, test, and ship faster across Freshdesk and Freshservice. · GitHub
it has all the functionalities, this can help you to solve your query.

Thanks

1 Like

I am not using the new React template, I created a test-app now based on the new template and I can see that the structure is very different.

I am going to have to test migrating one of our apps to the new template, but unfortunately I do not have time for that at the moment. I will try to remember to update here again with my results when I get there.

For now, thank you for the help!

Regards,
Henrik

1 Like