Hello again. Learning a lot with this stack, but I’ve another issue. When I run the build-after hook from Trellis, which basically runs:
- name: Run Acorn optimize
command: wp acorn optimize
args:
chdir: "{{ deploy_helper.new_release_path }}"
it breaks the stylesheet on my staging instance. Changing this to:
- name: Run Acorn optimize
command: wp acorn optimize:clear
args:
chdir: "{{ deploy_helper.new_release_path }}"
Makes it work again. Just adding this to see if a) I’m doing something wrong which is then requiring this addition and b) if someone else has the same issue.
Log1x
April 5, 2023, 7:16am
2
Are you running the latest Acorn?
What about your stylesheet is breaking?
Yes, I believe so, everything is a fresh install.
The break - whilst the stylesheet is there (and this is just on a base install of sage 10, with no additions or customisations) there is no css at all applied to the ‘welcome to wordpress’ screen.
I’ve restarted the whole process again on a new droplet, and tested at each instance - adding the deploy-after hook broke the css after a deploy; adding in :clear and deploying again brought it back up.
Log1x
April 5, 2023, 7:31am
4
Have you looked at dev console? Is the stylesheet URL wrong? Is the CSS not generated at all? Anything in the network tab?
OK I’ve ‘rebroken’ the site to investigate. It seems that the site is trying to find:
url/wp /app/themes/ceupress/public/css/app.8c2f5f.css
rather than
url/app/themes/ceupress/public/css/app.8c2f5f.css
For a similar reason, it’s breaking the JS too.
When I add back in the ‘clear’ statement, all works and directs fine
ben
April 6, 2023, 2:30pm
6
You might be hitting this bug:
opened 10:15AM - 10 May 22 UTC
bug
### Terms
- [X] I have read the [guidelines for Contributing to Roots Project… s](https://github.com/roots/.github/blob/master/CONTRIBUTING.md)
- [X] This request is not a duplicate of an existing issue
- [X] I have read the [docs](https://roots.io/docs/) and followed them (if applicable)
- [X] I have seached the [Roots Discourse](https://discourse.roots.io/) for answers and followed them (if applicable)
- [X] This is not a personal support request that should be posted on the [Roots Discourse](https://discourse.roots.io/) community
### Description
#### What's wrong?
When deploying a Sage 10 website, we have enabled `wp acorn optimize` as a build-after step in our fork of Trellis.
After running this command, the site tries to load the css from https://lcl.website.com/wp/app/themes/sage-dir, instead of https://lcl.website.com/app/themes/sage-dir.
#### What have you tried?
- Reproduced the issue locally by running `wp acorn optimize` and getting the same result.
- Extensive Googling, checked open/closed issues for Roots projects in the mix - Bud, Sage, Trellis and Acorn. Updated to latest Acorn to fix an initial issue with https which was resolved in 2.0.5
- Overriding the .env file to have a siteurl without /wp. When this is done, the `wp acorn optimize` command creates a config that works, but this wouldn't work with Bedrock afaik
- Tried hand correcting the file generated by acorn in sage-dir/storage/framework/cache/config.php, but this doesn't change the result
- Running composer install fixes it but I suspect just because it's clearing the cache folder
- Prepending `/..` to the config/assets.php URL works but it creates ugly URLs which contain ` https://lcl.website.com/../wp/app/themes/sage-dir,`
- Generated a working config.php by overriding .env file as before, ran a diff and all that was different was the "/wp" suffix for the Filesystems\Wordpress url & root values... but weirdly after switching back the URL and hand correcting this didn't change result. Did try regular `wp cache flush` but maybe there's another file based cache I'm not aware of?
- Tried reverting to Roots\asset instead of Roots\bundle, having the same issues which led me to believe it may be upstream in WP itself or arising from the combination of software we are using
- Did a bit of die(var_dump()) debugging within Roots\BundleContract, Roots\bundle, Roots\Asset, core WP Styles, wp_enqueue_styles and from all I can gather the caching of the config somehow triggers WP to choose the siteurl (which ends in `wp) for styles, even though it doesn't do so when cache hasn't been created and correcting that cache directly seems to not change anything.
- Deleting the config.php file triggers the CSS to load and the URL is correct in the html, making me wonder if either the files presence or another setting within it is causing this issue
- Tried https://github.com/roots/sage/issues/3031, changes a different setting and the file is still loaded from the wrong location
- We are using a fork of Trellis and Bedrock as well as a Sage 10 beta2 which has been manually updated from an older beta. It's possible we missed something in the configuration changes between versions or something unique to our setup is causing this. I am mid setup for testing a non modified copy of Trellis\Bedrock\Sage but that's quite time consuming to setup so just wanted to get this bug report up first as it's possible I'll run out of time pursuing that before I get anywhere.
- Checked multiple projects that are in Sage 10 beta1, Sage 10 beta2 and stable Sage 10 (10.1.6) - all have the same issue. All are using the same forks of Trellis and Bedrock
#### What insights have you gained?
- .env file setting of siteurl causes `wp acorn optimize` to work correctly but it's my understanding this will break things with Bedrock which requires /wp there. Also it works in a "live" way - if I generate the cached config and change the setting in env, it seems to use siteurl for stylesheets. If I don't cache configs, it's correctly using homeurl.
- Deleting the config.php file allows css to load again but changing it by hand does not
- This thread feels related https://discourse.roots.io/t/site-url-returning-wp/12270
#### Possible solutions
- Open to suggestions :)
#### Temporary workarounds
- Omit `wp acorn optimize` from deployments, not sure how impacting this is on performance but it seemed minimal on first glance
- Prefix the `/..` to assets.php, but this would be a last resort measure. Would almost rather just write our own script and link tags into the templates at that point.
### Steps To Reproduce
1. On a VM provisioned by Trellis
2. Setup a Bedrock website using Sage 10
3. Build frontend assets using Bud
4. Run `wp acorn optimize` to cache configs
5. Load the website in a browser and confirm CSS is not loading
6. Check CSS urls and confirm they contain `/wp/` after the public url of the site
### Expected Behavior
- CSS to load
- URLs generated by wp_enqueue_style to be consistent whether we have cached configs or not
### Actual Behavior
CSS cannot load as the URLs are invalid.
### Relevant Log Output
_No response_
### Versions
Acorn 2.0.5, Trellis 1.14.0, Sage 10 beta1,2 and 10.1.6, Bud 5.3.2, WP core 5.8.4, PHP 7.4, Ubuntu 20.04
1 Like
Thanks, that was the one, and the solution presented works. Unsure why this issue has presented itself; on the other site I’m building alongside this one, the issue didn’t arise, despite very similar setups.