roots/acorn

Bug: Using Sage/Acorn theme through symlink throws errors

oskar-koli opened this issue · 1 comments

Terms

Description

What's wrong?

I use Local for local development and prefer to symlink the theme into the local sites files as described here.
This works just fine with a more conventional Wordpress theme, but with a Sage theme a page load results in the following error:

Fatal error: Uncaught InvalidArgumentException: Unrecognized extension in file: ~/Local Sites/sage-test/app/public.
 in ~/projects/sage-test/vendor/illuminate/view/Factory.php on line 305

I posted about this in the Sage Community.

Possible solutions

I figured out that if I change line 44 in \Roots\Acorn\Sage\ViewFinder to:

- $this->path = $path ? realpath($path) : get_theme_file_path();
+ $this->path = realpath($path ?: get_theme_file_path());

then the crash no longer happens.
So I believe the issue is caused by how relative paths to view files are created in the ViewFinder class and this seems to fix the issue.

But I do not know the code base very well so I don't know if this may cause some unintended side effects?
I can make a pull request if this seems like an ok change!

Steps To Reproduce

  1. Install Local
  2. Create new local site
  3. Symlink a Sage/Acorn theme into the Local site's wp-content/themes directory
  4. Load page and see error

Expected Behavior

Sage/Acorn should work even through a symlink.

Actual Behavior

An error is thrown.

Relevant Log Output

Fatal error: Uncaught InvalidArgumentException: Unrecognized extension in file: ~/Local Sites/sage-test/app/public. in ~/projects/sage-test/vendor/illuminate/view/Factory.php on line 305
InvalidArgumentException: Unrecognized extension in file: ~/Local Sites/sage-test/app/public. in ~/projects/sage-test/vendor/illuminate/view/Factory.php on line 305
Call Stack
#	Time	Memory	Function	Location
1	0.0110	366624	{main}( )	.../index.php:0
2	0.0110	366936	require( '~/Local Sites/sage-test/app/public/wp-blog-header.php )	.../index.php:17
3	0.1352	3462552	require_once( '~/Local Sites/sage-test/app/public/wp-includes/template-loader.php )	.../wp-blog-header.php:19
4	0.1387	3527568	include( '~/projects/sage-test/index.php )	.../template-loader.php:106
5	0.1794	3835272	view( '~/Local Sites/sage-test/app/public', [] )	.../index.php:14
6	0.1794	3835272	Roots\view( $view = '~/Local Sites/sage-test/app/public', $data = [], $mergeData = ??? )	.../globals.php:13
7	0.1795	3835272	Illuminate\View\Factory->file( $path = '~/Local Sites/sage-test/app/public', $data = [], $mergeData = [] )	.../helpers.php:99
8	0.1795	3835272	Illuminate\View\Factory->viewInstance( $view = '~/Local Sites/sage-test/app/public', $path = '~/Local Sites/sage-test/app/public', $data = [] )	.../Factory.php:122
9	0.1795	3835432	Illuminate\View\Factory->getEngineFromPath( $path = '~/Local Sites/sage-test/app/public' )	.../Factory.php:274

Versions

v3.1.0

Darn, we spent half a day debugging the same thing and now that I wanted to document it, I see that @oskar-koli beat me to it… :/

Anyhow, we have the same problem, only for us, it's in production. Due to the way we deploy plug-ins and themes to our production sites, we're using symlinks for them.

While this worked fine with acorn 2, it break with version 3. The problem is that WordPress expects a path relative to the theme directory, but the code in ViewFinder.php will, for symlinked directories, produce paths like these:

../../../../somedir/releases/202307031847/theme-name/resources/views/page.blade.php

when we would need these:

resources/views/page.blade.php

And WordPress then creates these neat constructs in locate_template:

/var/www/html/wp-content/themes/theme-name/../../../../somedir/releases/202307031847/theme-name/resources/views/page.blade.php

The way we worked around it for now is to patch ViewFinder's constructor in a composer post-install-cmd:

+            "sed -i \"s/\\$path = ''/\\$path = STYLESHEETPATH/g\" src/themes/theme-name/vendor/roots/acorn/src/Roots/Acorn/Sage/ViewFinder.php"