enonic / lib-react4xp

React for XP: handling and rendering of pre-built React components in Enonic XP
Apache License 2.0
2 stars 2 forks source link

Error: Cannot read property "default" from undefined in <eval> #45

Closed espen42 closed 3 years ago

espen42 commented 4 years ago

Error message after big code dump on server side log, after server side rendering attempt:

ERROR: com.enonic.lib.react4xp.ssr.ServerSideRenderer.renderToString  |  Message: TypeError: Cannot read property "default" from undefined in <eval> at line number 1  |  Component

~Intermittent issue, the trigger circumstance is unclear. Code dump is mangled, so there's little help in the error message. Sometimes this error message is displayed in the log even though the rendered output is fine. Sometimes only the red error message placeholder is rendered.~

Currently, it looks like this message is only the default top-level error phrasing when the SSR encounters an error during renderToString and fails to render a component (which becomes the 'undefined' in the errror message).

So this error message obscures many other issues with components.

A different error message - the actual error - will often be visible at one of the "caused by" levels in the stack trace, when the error was first encountered (I've seen one instance where it only was reported the first time and required an XP restart for the actual error message to be visible again).

So this is an issue of "lifting" the actual error message from the stack trace to the "top level" that's reported in the fallback component rendering.

espen42 commented 4 years ago

On at least one occasion, this error message on the server side has been the result of trying to serverside-render faulty/problematic JSX. This error message then obscured the actual error message produced by the component. Clientside-rendering the component instead revealed the actual error message in the browser console.

espen42 commented 4 years ago

Seems related to cached-entry behavior: if an entry fails (to eval in nashorn in runtime), that entry is removed from the SSR entry-cache that stores the (compiled and pre-eval'ed) entries as props -> html functions. That means, the next time the entry is attempted again, it's not found under the entry name in the cache, which means the result will be undefined, and there's no default exported from it.

com.enonic.lib.react4xp.ssr.ServerSideRenderer:

            if (runMode == RunMode.PROD) {
                alreadyCachedAndRunAssetNames.remove(entry);
            }

As of recent updates, the added dev tips about rendering the entry in client-side should yield enough solution info for devs.

Still, this issue should be solved: if the name is not found in alreadyCachedAndRunAssetNames, a new attempt at render+cache should be implemented (or fixed).

espen42 commented 4 years ago

Currently, it looks like this message is only the default top-level error phrasing when the SSR encounters an error during renderToString and fails to render a component (which becomes the 'undefined' in the errror message).

So this error message obscures many other issues with components.

A different error message - the actual error - will often be visible at one of the "caused by" levels in the stack trace, when the error was first encountered (I've seen one instance where it only was reported the first time and required an XP restart for the actual error message to be visible again).

So this is an issue of "lifting" the actual error message from the stack trace to the "top level" that's reported in the fallback component rendering.