Can't Render Ninja Forms Preview With Sage 10, 504 Gateway Timeout

I have a Sage 10 theme and I can’t get the Ninja Forms previews to work. All they do is run forever and then just timeout? With any standard theme it renders fine. This breaks the previews from the Ninja Forms management area as well as in the Block Editor when placing a Ninja Forms block.

After waiting for it finally timeout on the preview I’m seeing the final errors:

[13-Jan-2023 21:12:24 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 4194312 bytes) in /var/www/html/web/wp-content/vendor/illuminate/view/FileViewFinder.php on line 137
[13-Jan-2023 21:12:24 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 2101248 bytes) in /var/www/html/web/wp/wp-includes/functions.php on line 5279
[13-Jan-2023 21:12:24 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 970752 bytes) in Unknown on line 0
[13-Jan-2023 21:13:07 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 4194312 bytes) in /var/www/html/web/wp-content/vendor/illuminate/view/FileViewFinder.php on line 137
[13-Jan-2023 21:13:08 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 2101248 bytes) in /var/www/html/web/wp/wp-includes/functions.php on line 5279
[13-Jan-2023 21:13:08 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 720896 bytes) in Unknown on line 0
[13-Jan-2023 21:13:20 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 4194312 bytes) in /var/www/html/web/wp-content/vendor/illuminate/view/FileViewFinder.php on line 137
[13-Jan-2023 21:13:20 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 2101248 bytes) in /var/www/html/web/wp/wp-includes/functions.php on line 5279
[13-Jan-2023 21:13:20 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 741376 bytes) in Unknown on line 0

So this appears to be some sort of View rendering issue.

Through some further debugging I came to point that perhaps with a URL ending in ?nf_preview_form=2 that it couldn’t properly determine the right view to pass to the Sage app. Sure enough it was passing the full path to the index.php file. I put in a check to force the view to a page and now things are rendering as expected.

Same here. Thanks for posting this.

Unfortunately, I’m thinking with an Acorn update. This is now no longer working. The error is now:

Target class [sage.view] does not exist.

I don’t believe we’ve changed anything related to Views in an Acorn update in a long time.

Is this only affecting your Ninja Form previews? It seems like it’d likely be a cache issue or a condition where your ThemeServiceProvider (which should extend Acorn’s SageServiceProvider) isn’t being loaded.

So, I found that I needed to yet again change the code to use

echo view( 'page' )->render();

instead of:

echo view( 'page', app( 'sage.data' ) )->render();

Like I had before. So there was definitely an update related to Acord/Sage. At least I finally found a fix for it.

It’s definitely not recommended to attempt to pass in app('sage.data') when using the view() helper yourself outside of the exception of Sage’s index.php. Global data is already passed to all rendered views from the Sage service provider in Acorn (and always has been).

It sounds like there was a lifecycle change somewhere. Glad you got it sorted.

I’m not clear on your statement. The default in index.php goes against what you are saying.

The app('sage.data') referenced in Sage’s index.php is for legacy compatibility allowing you to pass data via a filter for specific WordPress templates. You wouldn’t pass this when using the view() helper yourself.