Giter Club home page Giter Club logo

Comments (9)

gurkodil avatar gurkodil commented on June 27, 2024 1

Ah good to know! 👍 I can send a PR tomorrow if @d4rekanguok haven't fixed it already.

from netlify-cms-widgets.

d4rekanguok avatar d4rekanguok commented on June 27, 2024

Thank you for reporting in, I'll try to reproduce the error & see if I can fix it.

from netlify-cms-widgets.

gurkodil avatar gurkodil commented on June 27, 2024

It can be reproduced here:

https://custom-widgets.netlify.com/#/collections/posts/new

The componentDidMount method does not trigger on history changes, one solution could be to replace it with:

public componentWillReceiveProps(nextProps: WidgetProps) {
    const { value, field, onChange } = nextProps
    if (value) return
    // else generate id as previous in didMount...
}

I'm not really familar with lifecycle methods but I've tested it and it seems fine and fixes the bug. Or do you think there are some better solution?

from netlify-cms-widgets.

laurenskling avatar laurenskling commented on June 27, 2024

Yeah, you are not leaving the page, so didMount will not run again. componentWillReceiveProps is deprecated (https://reactjs.org/docs/react-component.html#updating)

The component would be better off using constructor and https://reactjs.org/docs/react-component.html#componentdidupdate to see if the value turned empty to create a new ID

from netlify-cms-widgets.

d4rekanguok avatar d4rekanguok commented on June 27, 2024

@gurkodil please do!

from netlify-cms-widgets.

d4rekanguok avatar d4rekanguok commented on June 27, 2024

The widget worked as expected now, thanks again @gurkodil @laurenskling! Published in @ncwidgets/[email protected]

from netlify-cms-widgets.

laurenskling avatar laurenskling commented on June 27, 2024

I'm still seeing componentDidMount after installing 0.5.1 🤔

from netlify-cms-widgets.

d4rekanguok avatar d4rekanguok commented on June 27, 2024

@laurenskling ugh, sorry that the issue still persists after the update. Could it be a cache issue on your side? I've checked the built js file here, the changes have been applied:

// https://unpkg.com/@ncwidgets/[email protected]/dist/control.js

class Control extends React.Component {
    constructor(props) {
        super(props);
        if (props.value)
            return;
        this.generateId();
    }
    generateId() {
        const { field, onChange } = this.props;
        const usePrefix = field.get('prefix');
        const useTimestamp = field.get('timestamp');
        const prefix = usePrefix ? usePrefix + '-' : '';
        const timestamp = useTimestamp ? Date.now() + '-' : '';
        const id = prefix + timestamp + shortid_1.default();
        onChange(id);
    }
    componentDidUpdate() {
        if (this.props.value)
            return;
        this.generateId();
    }
    render() {
        const { forID, classNameWrapper, setActiveStyle, setInactiveStyle, value, } = this.props;
        return (React.createElement("input", { type: 'text', className: classNameWrapper, style: {
                color: '#cdcdcd',
            }, value: value || '', id: forID, onFocus: setActiveStyle, onBlur: setInactiveStyle, disabled: true }));
    }
}
exports.Control = Control;

I've also tried the component in a codesandbox, and the component does generate a new id when using 'Publish and create new' option : https://codesandbox.io/s/netlify-cms-app-example-h5n43?fontsize=14&hidenavigation=1&theme=dark

from netlify-cms-widgets.

laurenskling avatar laurenskling commented on June 27, 2024

Just installed it correctly! Must have been some caching issue https://shouldiblamecaching.com/

Thanks so much!

from netlify-cms-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.