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

Custom component error when rendering messages from history #203

Open
eugeniumegherea opened this issue Mar 24, 2020 · 0 comments
Open

Custom component error when rendering messages from history #203

eugeniumegherea opened this issue Mar 24, 2020 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@eugeniumegherea
Copy link

Version: 0.7.23
Consider following code:

  render() {
    return (
      <Fragment>
        {
          this.state.initialized && (
            <Widget
              ref={ el => this.addListeners(el) }
              {...this.props}
              customComponent={ev => this.renderCustomComponent(ev)}
            />
          )
        }
      </Fragment>
    );
  }

  private renderCustomComponent(msg: any) {
    const dangerousHtml = {
      __html: msg.custom.htmlContent
    };

    return (
      <div className="response">
        <div className="message-text">
          <div className="markdown" dangerouslySetInnerHTML={ dangerousHtml }></div>
        </div>
      </div>
    );
  }

Message payload looks like this:

{
   custom: {
        htmlContent: "<button>some button</button>"
   }
}

When I get this message live from rasa, custom component renders it properly. If I do a page refresh, it will try to render history and I get an error in console that msg.custom is undefined. Upon debugging source code found out that message props are not passed in correctly in custom component. This is the message I get, there is no key named custom at all, but it's there, it's just not properly passed as prop. (See _root prop and it's entries)
image

I think the way props are passed is just wrong because ...message.get('props') returns another immutable instance, not a proper json we need. I think it might be that when the message is live, it's not an immutable instance but a simple json and that's why it's working.

return <ComponentToRender id={index} {...message.get('props')} isLast={isLast} />;

I would really appreciate some input on this
Thanks

@MatthieuJnon MatthieuJnon added the bug Something isn't working label Jul 31, 2020
@MatthieuJnon MatthieuJnon self-assigned this Jul 31, 2020
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

No branches or pull requests

2 participants