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

Components folders config isn't additive contrary to what the docs say #1057

Closed
hteumeuleu opened this issue Sep 4, 2023 · 4 comments · Fixed by #1058
Closed

Components folders config isn't additive contrary to what the docs say #1057

hteumeuleu opened this issue Sep 4, 2023 · 4 comments · Fixed by #1058
Labels
bug Something isn't working

Comments

@hteumeuleu
Copy link

  • Maizzle Version: 4.5.0
  • Node.js Version: 18.16.0

The documentation for the components folders configuration (https://maizzle.com/docs/configuration/components) states that “The paths you defined will be added to the default folders.” This is not what happens in my experience.

What I did:

  1. npx degit maizzle/maizzle my-project and npm i
  2. In src, add an includes folder with a file named header.html.
  3. In the promotional.html template, add an <x-header> tag.
  4. In config.js, add the following config under build:
    components: {
      folders: ['src/includes'],
    },
  1. npm run build

Result:

✖ Failed to compile template: promotional.html
⚠ [components] <x-v-fill> could not find v-fill.html in the defined root paths (src/includes, src/layouts, src/templates, src/includes)

The components in src/components/ can no longer be found. I need to manually add all the default folders for it to work properly.

@cossssmin
Copy link
Member

cossssmin commented Sep 4, 2023

Thanks for catching this, there's an issue with lodash.merge and how it merges the default components config with the user-provided one. Will fix it in today's release.

Note: got bitten by their array merge strategy.

@cossssmin cossssmin added the bug Something isn't working label Sep 4, 2023
@cossssmin
Copy link
Member

Should be fixed in latest v4.6.0, let me know if you're still having issues.

@cossssmin
Copy link
Member

Coming back to this as the custom implementation of merge has an issue that results in duplication of array items.

Specifically, something like this will be duplicated at least once, and it goes up depending on the number of front matter variables (I know it sounds weird, it's because of a stupid for loop):

module.exports = {
  locals: {
    columns: [
      {
          title: "one",
      },
      {
          title: "two",
      },
      {
          title: "three",
      },
      {
          title: "four",
      },
    ]
  },
}

This can be a problem if you're looping through data, as it will render title at least 8 times instead of 4.

I've tested using lodash.merge again with your example and it works fine, it may have been fixed in a dependency update in posthtml-component. Will test some more and will probably revert in the next release

@cossssmin cossssmin reopened this Dec 29, 2023
cossssmin added a commit that referenced this issue Dec 29, 2023
undo #1058 as it caused data duplication, explained in #1057
@cossssmin
Copy link
Member

Published v4.6.3, try it out and let me know if anything 👍

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

Successfully merging a pull request may close this issue.

2 participants