Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: enqueueCss() not working as expected #229

Closed
5 tasks done
tedw opened this issue May 31, 2022 · 1 comment
Closed
5 tasks done

Bug: enqueueCss() not working as expected #229

tedw opened this issue May 31, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@tedw
Copy link

tedw commented May 31, 2022

Terms

Description

What's wrong?

enqueueCss() doesn’t work when there’s only a single CSS file as the entry point.

bud.entry({
  app: ['@scripts/main', '@styles/main.scss'],
  login: '@styles/login.scss'
})
  .splitChunks(false)
  .runtime(false)
  .assets('images')
  .watch('resources/views/**/*', 'app/**/*')
  .proxy('http://my-app-name.lndo.site')
  .serve('http://localhost:3000');
add_action('login_enqueue_scripts', function() {
    bundle('login')->enqueueCss();
});

What have you tried?

It works if you add another file to the login entry. It also works if you downgrade @roots/bud to version 5.8.3 and use enqueue() instead. However, starting at version 5.8.4 neither enqueueCss() nor enqueue() works when there is a single file.

What insights have you gained?

I suspect this Bud update below is reason why it’s failing, but I think the root cause is with Acorn.

Here’s the error message:

Here’s the relevant line in /app/vendor/roots/acorn/src/Roots/Acorn/Assets/Bundle.php:36

if (Arr::isAssoc($this->bundle['js'])) {

Possible solutions

I’m not super familiar with the codebase yet but I’m hoping it’s as easy as updating the line referenced above.

Temporary workarounds

Create an empty JS file and add it to the entry point:

bud.entry({
  app: ['@scripts/main', '@styles/main.scss'],
  login: ['@scripts/empty', '@styles/login.scss']
})

Another option is to downgrade to Bud 5.8.3 and use enqueue().

Steps To Reproduce

  1. Add a single CSS as an entry point in bug.config.js
  2. Attempt to enqueue that CSS file using bundle('example')->enqueueCss();
  3. Run bud build
  4. Open page that should have the custom CSS file in the browser

Expected Behavior

The CSS file should have been enqueued normally.

Actual Behavior

An error was thrown

Relevant Log Output

Fatal error: Uncaught Error: Argument 1 passed to Illuminate\Support\Arr::isAssoc() must be of the type array, null given, called in /app/vendor/roots/acorn/src/Roots/Acorn/Assets/Bundle.php on line 136
in /app/vendor/illuminate/collections/Arr.php on line 406

Call stack:

Illuminate\S\Arr::isAssoc()
/app/vendor/roots/acorn/src/Roots/Acorn/Assets/Bundle.php:136
Roots\A\A\Bundle::setRuntime()
/app/vendor/roots/acorn/src/Roots/Acorn/Assets/Bundle.php:36
Roots\A\A\Bundle::__construct()
/app/vendor/roots/acorn/src/Roots/Acorn/Assets/Manifest.php:56
Roots\A\A\Manifest::bundle()
/app/vendor/roots/acorn/src/Roots/helpers.php:36
Roots\bundle()
wp-content/themes/[redacted]/app/setup.php:19
App\{closure}()
wp-includes/class-wp-hook.php:307
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:331
WP_Hook::do_action()
wp-includes/plugin.php:476
do_action()
wp-login.php:114
login_header()
wp-login.php:1383

Versions

Sage 10, Acorn 2.0.6, Bud 5.8.0

@tedw tedw added the bug Something isn't working label May 31, 2022
@QWp6t QWp6t self-assigned this Jun 1, 2022
QWp6t added a commit that referenced this issue Jun 26, 2022
When an entrypoint only contains CSS and no JS, this will cause
an error.

This fix alleviates that by adding empty arrays for all supported
entrypoint extensions when none are contained in the bundle.

closes #229
@QWp6t
Copy link
Member

QWp6t commented Jun 26, 2022

Fixed in #230 (4fd1c43)

@QWp6t QWp6t closed this as completed Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants