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

Incorrect mapping over this.props.widgetsFor in Custom preview #1089

Closed
crgeary opened this issue Feb 7, 2018 · 5 comments
Closed

Incorrect mapping over this.props.widgetsFor in Custom preview #1089

crgeary opened this issue Feb 7, 2018 · 5 comments

Comments

@crgeary
Copy link

crgeary commented Feb 7, 2018

- Do you want to request a feature or report a bug?

BUG

- What is the current behavior?

The following code within a PreviewTemplate outputs the words data & widgets when there are no images to map over.

this.props.widgetsFor('images').map(function (image, index) {

});

- If the current behavior is a bug, please provide the steps to reproduce.

  1. Visit - https://practical-leavitt-aada1c.netlify.com/admin/
  2. Click "Login" (there is no password)
  3. Click "New Pages"
  4. View the Preview

- What is the expected behavior?

I would expect the above block of code to run per "image" in the "images" data. If there are no images, then there should be nothing to map over.

- Please mention your CMS, node.js, and operating system version.

Netlify CMS v1.1

- Please link or paste your config.yml below if applicable.

I've made a repo containing as a little as possible to show the issue:


Please let me know if there is anything more I can do to help.

@erquhart
Copy link
Contributor

erquhart commented Feb 8, 2018

Seems to only happen on initial load - if you add an item to the list and then remove it, the preview text is blank.

@mdavidmorton
Copy link

mdavidmorton commented Feb 27, 2018

Ran into this same problem today. Solution below isn't great long term, but it bypasses the data widgets text:

/* Assign to variable before render() return statement */
var images = this.props.widgetsFor('images'); 

/* Other code */

h('div', {'className': 'band band--md'}, (images.first() != undefined)
    ? images.map(function (image, index) {
        if (!image || !image.getIn(['data', 'src'])) { return ; }
        
        return h('div', {'key': index},
            this.props.getAsset(image.getIn(['data', 'src'])).toString()
        );
      })
    : h('div', {}, '')
)

@tech4him1
Copy link
Contributor

Adding a default value to the list widget should fix this (#977).

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale label Oct 29, 2019
@martinjagodic
Copy link
Member

Closing as stale and/or outdated.

@martinjagodic martinjagodic closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants