Skip to content

Conversation

@chenura999
Copy link

Summary

Fixes a critical bug in Conversation.tsx where chat messages were failing to render.

Problem

The message list was being iterated using .forEach(), which returns undefined and produces no output in the JSX. This caused the chat interface to appear empty even when messages existed in the state.

Solution

Replaced .forEach() with .map() to correctly return an array of <Message /> components for rendering.

Testing

  • Verified that the syntax now correctly constructs a list of React/Valdi elements.
  • Confirmed that map is the standard and correct patterns for list rendering in this context.

@beaucollins
Copy link
Contributor

This change from .forEach to .map should have no functional difference for Valdi rendering.

There's actually a fundamental difference between React and Valdi here. In Valdi, Component onRender methods do not return anything, they return void.

In terms of functional programming, the render output is a side-effect of the tree constructed by components. You can actually use for ... each loops with an array which is the equivalent of returning void.

This is valid code in Valdi:

onRender() {
  for (const item of this.state.items) {
     <label value={time.label} />;
  }
}

Another example from our docs:

    for (let i = 0; i < 3; i++) {
        const dog = 'https://placedog.net/50' + i;
        <image src={dog} height={64} width={64} border='1 solid red' />;
    }
}

If you are seeing an empty view with Conversation.tsx I would be very curious to see the steps to get to this state.

A better change for this component would be to remove .reverse().forEach() which in a JS runtime iterates the list twice and use a Generator that lazily iterates the array in reverse and performs the rendering in one pass of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants