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

[request] wpjson.settings callback fn required to return passed theme instance; missing generated theme.json parts otherwise #2168

Closed
3 tasks done
strarsis opened this issue Mar 16, 2023 · 2 comments
Labels
enhancement New feature or request stale

Comments

@strarsis
Copy link

Agreement

Describe the issue

The wpjson.settings callback function has to return the theme instance which it got passed as argument,
as otherwise parts of generated theme.json will be missing, and not just the parts added after the callback function.

Expected Behavior

No missing parts of generated theme.json, even if the callback function does not return the theme instance.

Actual Behavior

Parts of theme.json is missing when the callback function does not return the theme instance:

Steps To Reproduce

  1. Start with a default Sage theme with default bud configuration.
  2. Run the bud build. (Optional: Keep/copy generated theme.json for later comparison with a newly generated theme.json).
  3. Add to bud config a wpjson.settings invocation with a callback function that does not return the theme instance that was passed to it as argument:
// [...]
      .settings(theme => {
        // logic that does not return `theme`
       // return theme; // do not return `theme` instance to reproduce this issue
      })
// [...]
  1. Run the bud build, note that parts of newly generated theme.json are missing now.

version

6.9.1

Logs

No notices, warnings or errors were logged.

Configuration

Default `bud` config file, except for the added `wpjson.settings` for reproducing this issue.

Relevant .budfiles

No response

@strarsis strarsis added the bug Something isn't working label Mar 16, 2023
@strarsis strarsis changed the title [bug] wpjson.settings callback fn requires theme being returned by function [bug] wpjson.settings callback fn required to return passed theme instance Mar 16, 2023
@strarsis strarsis changed the title [bug] wpjson.settings callback fn required to return passed theme instance [bug] wpjson.settings callback fn required to return passed theme instance, missing generated theme.json parts otherwise Mar 16, 2023
@strarsis strarsis changed the title [bug] wpjson.settings callback fn required to return passed theme instance, missing generated theme.json parts otherwise [bug] wpjson.settings callback fn required to return passed theme instance; missing generated theme.json parts otherwise Mar 16, 2023
@kellymears
Copy link
Member

kellymears commented Mar 16, 2023

I'm willing to hear out arguments for the behavior being different, but this function is working as intended (and as documented).

It gives you the object and asks you to return something:

export interface Mutator {
  (
    json:
      | Partial<Theme.GlobalSettingsAndStyles['settings']>
      | Container<Partial<Theme.GlobalSettingsAndStyles['settings']>>,
  ):
    | Partial<Theme.GlobalSettingsAndStyles['settings']>
    | Container<Partial<Theme.GlobalSettingsAndStyles['settings']>>
}

interface settings {
  (
    input?:
      | Mutator
      | Container<Partial<Theme.GlobalSettingsAndStyles['settings']>>
      | Partial<Theme.GlobalSettingsAndStyles['settings']>
      | boolean,
    raw?: boolean,
  ): this
}

I think it's more confusing for this function to not use what is returned as a value. And it's pretty easy to always return a value with arrow fns and the container interface:

bud.wpjson.settings(theme => theme
  .set('color.custom', false)
  .set('color.customDuotone', false)
)

Regardless, wpjson.settings should arguably be deprecated in #2079 (currently not planning on that). But, I would use bud.wpjson.set over bud.wpjson.settings (PR soon on sage itself):

bud.wpjson
  .set(`settings.color.custom`, false)
  .set(`settings.color.customDuotone`, false)
  .set(`settings.color.customGradient`, false)
  .set(`settings.color.defaultDuotone`, false)

@kellymears kellymears added enhancement New feature or request and removed bug Something isn't working labels Mar 16, 2023
@kellymears kellymears changed the title [bug] wpjson.settings callback fn required to return passed theme instance; missing generated theme.json parts otherwise [request] wpjson.settings callback fn required to return passed theme instance; missing generated theme.json parts otherwise Mar 16, 2023
@github-actions
Copy link

Message to comment on stale issues. If none provided, will not mark issues stale

@github-actions github-actions bot added the stale label May 16, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

2 participants