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

Do not fatal if manifest is missing (type hinting) #41

Closed
kadamwhite opened this issue Jun 16, 2022 · 4 comments
Closed

Do not fatal if manifest is missing (type hinting) #41

kadamwhite opened this issue Jun 16, 2022 · 4 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@kadamwhite
Copy link
Collaborator

(extracted from a comment on #40)

Probably the biggest risk / gotcha I run into regularly with Asset Loader right now is that if you try to enqueue a file and there is no manifest on disk, get_asset_manifest() returns null which is not a string which causes a 500.

Argument 1 passed to Asset_Loader\enqueue_asset() must be of the type string, null given

This is a rough edge we should probably smooth off, by one or more of

  • removing the type constraint
  • making the manifest function return an empty string instead of null
  • and possibly log a warning within (enqueue|register)_asset if the manifest is missing

I'm personally most in favor of removing the constraint and possibly adding an error, but curious for thoughts. @Sephsekla et al

@Sephsekla
Copy link
Contributor

I think the biggest issue is that it's inconsistent with the behaviour of wp_enqueue_script tbh. In a way I kinda like the fatal, since you'll immediately know about it if a critical asset is missing.

What do you think about some kind of strict mode flag/argument which lets a user decide whether it fatally errors?

@kadamwhite
Copy link
Collaborator Author

Not particularly font of strict modes, it's another layer you need to keep in mind on top of environment, WP_Debug, etc. 🤔

My rough stance here is that there's many things that can cause a build to fail, and I wouldn't want the site to fatal if a plugin was activated without a build process in place or in a situation where assets didn't get omitted as expected. On the sort of sites we work on, as an example, if we were adding a blocks plugin I'd consider it much more desirable to have the site load sans those blocks than to fail to load entirely.

@kadamwhite kadamwhite added this to the v1.0 Release milestone Jun 16, 2022
@kadamwhite kadamwhite added the help wanted Extra attention is needed label Jun 16, 2022
@Sephsekla
Copy link
Contributor

Not particularly font of strict modes, it's another layer you need to keep in mind on top of environment, WP_Debug, etc. 🤔

OK so maybe an explicit argument in the functions?

function enqueue_asset( string $manifest_path, string $target_asset, array $options = [], bool $strict_require = false );

For something like GDPR cookie code for example, it might be desired behaviour to break rather than miss the script.

@kadamwhite
Copy link
Collaborator Author

Fixed in #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants