This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 819
Log TimelinePanel
debugging info when opening the bug report modal
#8502
Merged
MadLittleMods
merged 13 commits into
develop
from
madlittlemods/debug-logs-for-timeline-panel
May 10, 2022
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2861486
Log TimelinePanel debuggin info when opening the bug report modal
MadLittleMods c15cac9
Fix up some lints
MadLittleMods 2d61cbe
Merge branch 'develop' into madlittlemods/debug-logs-for-timeline-panel
MadLittleMods 144e23b
Add some descriptive comments
MadLittleMods 03ef042
Better comment, only speak when spoken to 😁
MadLittleMods 3307c4e
Address review
MadLittleMods 18c9970
Use built in dispatcher
MadLittleMods c597c96
Fix lints
MadLittleMods cfa4757
No need to grab the txn-id since local echo events have event.getId()…
MadLittleMods 0dc63a6
Verbally type payload
MadLittleMods e3793d6
Merge branch 'develop' into madlittlemods/debug-logs-for-timeline-panel
turt2live 7baaaff
Merge branch 'develop' into madlittlemods/debug-logs-for-timeline-panel
MadLittleMods de3b758
Merge branch 'madlittlemods/debug-logs-for-timeline-panel' of github.…
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,6 +372,69 @@ class TimelinePanel extends React.Component<IProps, IState> { | |
} | ||
} | ||
|
||
/** | ||
* Logs out debug info to describe the state of the TimelinePanel and the | ||
* events in the room according to the matrix-js-sdk. This is useful when | ||
* debugging problems like messages out of order, or messages that should | ||
* not be showing up in a thread, etc. | ||
* | ||
* It's too expensive and cumbersome to do all of these calculations for | ||
* every message change so instead we only log it out when asked. | ||
*/ | ||
private onDumpDebugLogs = (): void => { | ||
const roomId = this.props.timelineSet.room?.roomId; | ||
// Get a list of the event IDs used in this TimelinePanel. | ||
// This includes state and hidden events which we don't render | ||
const eventIdList = this.state.events.map((ev) => ev.getId()); | ||
|
||
// Get the list of actually rendered events seen in the DOM. | ||
// This is useful to know for sure what's being shown on screen. | ||
// And we can suss out any corrupted React `key` problems. | ||
let renderedEventIds: string[]; | ||
const messagePanel = this.messagePanel.current; | ||
if (messagePanel) { | ||
const messagePanelNode = ReactDOM.findDOMNode(messagePanel) as Element; | ||
if (messagePanelNode) { | ||
const actuallyRenderedEvents = messagePanelNode.querySelectorAll('[data-event-id]'); | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
renderedEventIds = [...actuallyRenderedEvents].map((renderedEvent) => { | ||
return renderedEvent.getAttribute('data-event-id'); | ||
}); | ||
} | ||
} | ||
|
||
// Get the list of events and threads for the room as seen by the | ||
// matrix-js-sdk. | ||
let serializedEventIdsFromTimelineSets: { [key: string]: string[] }[]; | ||
let serializedEventIdsFromThreadsTimelineSets: { [key: string]: string[] }[]; | ||
const serializedThreadsMap: { [key: string]: string[] } = {}; | ||
const client = MatrixClientPeg.get(); | ||
const room = client?.getRoom(roomId); | ||
if (room) { | ||
const timelineSets = room.getTimelineSets(); | ||
const threadsTimelineSets = room.threadsTimelineSets; | ||
|
||
// Serialize all of the timelineSets and timelines in each set to their event IDs | ||
serializedEventIdsFromTimelineSets = serializeEventIdsFromTimelineSets(timelineSets); | ||
serializedEventIdsFromThreadsTimelineSets = serializeEventIdsFromTimelineSets(threadsTimelineSets); | ||
|
||
// Serialize all threads in the room from theadId -> event IDs in the thread | ||
room.getThreads().forEach((thread) => { | ||
serializedThreadsMap[thread.id] = thread.events.map(ev => ev.getId()); | ||
}); | ||
} | ||
|
||
logger.debug( | ||
`TimelinePanel(${this.context.timelineRenderingType}): Debugging info for ${roomId}\n` + | ||
`\tevents(${eventIdList.length})=${JSON.stringify(eventIdList)}\n` + | ||
`\trenderedEventIds(${renderedEventIds ? renderedEventIds.length : 0})=` + | ||
`${JSON.stringify(renderedEventIds)}\n` + | ||
`\tserializedEventIdsFromTimelineSets=${JSON.stringify(serializedEventIdsFromTimelineSets)}\n` + | ||
`\tserializedEventIdsFromThreadsTimelineSets=` + | ||
`${JSON.stringify(serializedEventIdsFromThreadsTimelineSets)}\n` + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confusingly, Thought it was relevant to log but could also be dropped or moved to |
||
`\tserializedThreadsMap=${JSON.stringify(serializedThreadsMap)}`, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These logs look like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any other info that would be useful to have? |
||
}; | ||
|
||
private onMessageListUnfillRequest = (backwards: boolean, scrollToken: string): void => { | ||
// If backwards, unpaginate from the back (i.e. the start of the timeline) | ||
const dir = backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS; | ||
|
@@ -529,6 +592,9 @@ class TimelinePanel extends React.Component<IProps, IState> { | |
case "ignore_state_changed": | ||
this.forceUpdate(); | ||
break; | ||
case Action.DumpDebugLogs: | ||
this.onDumpDebugLogs(); | ||
break; | ||
} | ||
}; | ||
|
||
|
@@ -1465,7 +1531,7 @@ class TimelinePanel extends React.Component<IProps, IState> { | |
const messagePanel = this.messagePanel.current; | ||
if (!messagePanel) return null; | ||
|
||
const messagePanelNode = ReactDOM.findDOMNode(messagePanel) as HTMLElement; | ||
const messagePanelNode = ReactDOM.findDOMNode(messagePanel) as Element; | ||
if (!messagePanelNode) return null; // sometimes this happens for fresh rooms/post-sync | ||
const wrapperRect = messagePanelNode.getBoundingClientRect(); | ||
const myUserId = MatrixClientPeg.get().credentials.userId; | ||
|
@@ -1687,4 +1753,30 @@ class TimelinePanel extends React.Component<IProps, IState> { | |
} | ||
} | ||
|
||
/** | ||
* Iterate across all of the timelineSets and timelines inside to expose all of | ||
* the event IDs contained inside. | ||
* | ||
* @return An event ID list for every timeline in every timelineSet | ||
*/ | ||
function serializeEventIdsFromTimelineSets(timelineSets): { [key: string]: string[] }[] { | ||
const serializedEventIdsInTimelineSet = timelineSets.map((timelineSet) => { | ||
const timelineMap = {}; | ||
|
||
const timelines = timelineSet.getTimelines(); | ||
const liveTimeline = timelineSet.getLiveTimeline(); | ||
|
||
timelines.forEach((timeline, index) => { | ||
// Add a special label when it is the live timeline so we can tell | ||
// it apart from the others | ||
const isLiveTimeline = timeline === liveTimeline; | ||
timelineMap[isLiveTimeline ? 'liveTimeline' : `${index}`] = timeline.getEvents().map(ev => ev.getId()); | ||
}); | ||
|
||
return timelineMap; | ||
}); | ||
|
||
return serializedEventIdsInTimelineSet; | ||
} | ||
|
||
export default TimelinePanel; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.