[Bug] - Message datetime uses render time even when a saved timestamp is supplied

未关闭
#938 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
react, typescript
领域
frontend

调研方向

Start in packages/module/src/Message/Message.tsx, where a new Date() is created during render and passed to the nested Timestamp component. Check how the timestamp prop is used for display and whether a date value can be forwarded alongside it. Done means the time element's datetime attribute matches the supplied instant and stays stable across rerenders; the API shape is still open, so confirm it with maintainers before coding.

由索引模型根据 Issue 内容生成。

描述

Description

When a saved timestamp is passed to Message, the visible timestamp and the message section's accessible label correctly use the supplied string. However, the underlying <time datetime="..."> attribute still contains the time of rendering. It also changes on subsequent renders.

This makes the machine-readable timestamp disagree with the displayed message time. Consumers can supply timestamp?: string, but cannot supply the actual date to the nested PatternFly Timestamp component.

The implementation creates const date = new Date() during rendering and uses <Timestamp date={date}>{timestamp}</Timestamp>:
https://github.com/patternfly/chatbot/blob/aca7848d3212003a20ebcd916217e9d29c9862e6/packages/module/src/Message/Message.tsx

Expected: Consumers should be able to provide the saved message instant so that both the displayed timestamp and the HTML datetime describe that instant and remain stable across rerenders.

Actual: Supplying timestamp fixes the displayed text, but datetime continues to describe render time.

Related reports #448 and #299, and documentation PR #302, explain that applications must supply persistent timestamps. This report concerns the remaining HTML datetime mismatch even after following that guidance.

A possible backward-compatible solution is an optional date prop forwarded to the native Timestamp, while retaining the existing display-string prop and default behavior. The API shape is open for discussion; localized display strings should not need to be parsed to recover the date.

Steps to Reproduce
  1. Render the example below using @patternfly/chatbot.
  2. Inspect the <time> element inside the message in browser developer tools.
  3. Notice that its text is the supplied historical timestamp, while its datetime attribute is the current render time rather than 2025-01-15T10:00:00.000Z.
  4. Wait a few seconds, then click Rerender.
  5. Inspect the same element again: the displayed text remains unchanged, but datetime has advanced.
Data/JSON Context (if applicable)
import { useState } from 'react';
import { Message } from '@patternfly/chatbot';

export default function TimestampReproduction() {
  const [renderCount, setRenderCount] = useState(0);

  return (
    <>
      <button onClick={() => setRenderCount((count) => count + 1)}>
        Rerender ({renderCount})
      </button>
      <Message
        role="user"
        name="You"
        content="A saved message"
        timestamp="2025-01-15 10:00:00 UTC"
      />
    </>
  );
}
Environment
  • PatternFly Chatbot: 6.7.1
  • PatternFly React Core: 6.6.1
  • React: 19.3.0
  • Browser: Chromium (exact version not recorded)
  • Viewport: observed in desktop chat; the date is generated in the component independently of layout
  • The same timestamp implementation is present in the linked upstream source revision.
Screenshots or Logs

DOM inspection of a saved conversation showed the following values (displayed text was in Asia/Kolkata, UTC+05:30):

Field Value
Visible timestamp 02/11/2026, 13:14:56
Expected datetime for that saved instant 2026-11-02T07:44:56.000Z
Actual datetime when the conversation was reopened 2026-11-02T08:25:39.646Z

The supplied visible timestamp remained correct; the HTML attribute represented the later render time.

主要语言
TypeScript
星标
9
派生
39
平均合并
3 天 1 小时
30 天内合并 PR
15

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

patternfly/chatbot 的其他 Issue

查看 patternfly/chatbot 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。