Skip to content

perf: skip message skeleton if it is cached #10750

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

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions src/components/ThreadEnvelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@
</template>
</div>
</div>
<MessageLoadingSkeleton v-if="loading !== LOADING_DONE" />
<Message v-if="message && loading !== LOADING_MESSAGE"
v-show="loading === LOADING_DONE"
<MessageLoadingSkeleton v-if="loading === Loading.Skeleton" />
<Message v-if="message"
v-show="loading === Loading.Done"
:envelope="envelope"
:message="message"
:full-height="fullHeight"
:smart-replies="showFollowUpHeader ? [] : smartReplies"
:reply-button-label="replyButtonLabel"
@load="loading = LOADING_DONE"
@load="onMessageLoaded"
@reply="(body) => onReply(body, showFollowUpHeader)" />
<Error v-else-if="error"
:error="error.message || t('mail', 'Not found')"
Expand Down Expand Up @@ -318,9 +318,11 @@ import useMainStore from '../store/mainStore.js'
import { mapStores } from 'pinia'

// Ternary loading state
const LOADING_DONE = 0
const LOADING_MESSAGE = 1
const LOADING_BODY = 2
const Loading = Object.seal({
Done: 0,
Silent: 1,
Skeleton: 2,
})

export default {
name: 'ThreadEnvelope',
Expand Down Expand Up @@ -394,16 +396,14 @@ export default {
},
data() {
return {
loading: LOADING_DONE,
loading: Loading.Done,
showListUnsubscribeConfirmation: false,
error: undefined,
message: undefined,
importantSvg,
unsubscribing: false,
seenTimer: undefined,
LOADING_BODY,
LOADING_DONE,
LOADING_MESSAGE,
Loading,
recomputeMenuSize: 0,
moreActionsOpen: false,
smartReplies: [],
Expand All @@ -417,6 +417,7 @@ export default {
rawMessage: '', // Will hold the raw source of the message when requested
isInternal: true,
enabledSmartReply: loadState('mail', 'llm_freeprompt_available', false),
loadingBodyTimeout: undefined,
}
},
computed: {
Expand Down Expand Up @@ -595,11 +596,11 @@ export default {
this.fetchMessage()
} else {
this.message = undefined
this.loading = LOADING_DONE
this.loading = Loading.Done
}
},
loading(loading) {
if (loading === LOADING_DONE) {
if (loading === Loading.Done) {
this.$emit('loaded')
}
},
Expand Down Expand Up @@ -642,16 +643,35 @@ export default {
filterSubject(value) {
return value.replace(/((?:[\t ]*(?:R|RE|F|FW|FWD):[\t ]*)*)/i, '')
},
onMessageLoaded() {
if (this.loadingBodyTimeout) {
clearTimeout(this.loadingBodyTimeout)
this.loadingBodyTimeout = undefined
}

this.loading = Loading.Done
},
async fetchMessage() {
this.loading = LOADING_MESSAGE
this.error = undefined
let loadingTimeout
const isCached = !!this.mainStore.getMessage(this.envelope.databaseId)
if (!isCached) {
loadingTimeout = setTimeout(() => {
this.loading = Loading.Skeleton
}, 200)
}

this.loading = Loading.Silent
this.error = undefined
logger.debug(`fetching thread message ${this.envelope.databaseId}`)

try {
this.message = await this.mainStore.fetchMessage(this.envelope.databaseId)
logger.debug(`message ${this.envelope.databaseId} fetched`, { message: this.message })

if (loadingTimeout) {
clearTimeout(loadingTimeout)
}

if (!this.envelope.flags.seen && this.hasSeenAcl) {
logger.info('Starting timer to mark message as seen/read')
this.seenTimer = setTimeout(() => {
Expand All @@ -661,16 +681,18 @@ export default {
}

if (this.message.hasHtmlBody) {
this.loading = LOADING_BODY
this.loadingBodyTimeout = setTimeout(() => {
this.loading = Loading.Skeleton
}, 200)
} else {
this.loading = LOADING_DONE
this.loading = Loading.Done
}
this.$nextTick(() => {
this.handleThreadScrolling()
})
} catch (error) {
this.error = error
this.loading = LOADING_DONE
this.loading = Loading.Done
logger.error('Could not fetch message', { error })
}

Expand Down
4 changes: 4 additions & 0 deletions src/store/mainStore/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,10 @@ export default function mainStoreActions() {
})
},
async fetchMessage(id) {
if (this.messages[id]) {
return this.messages[id]
}

return handleHttpAuthErrors(async () => {
const message = await fetchMessage(id)
// Only commit if not undefined (not found)
Expand Down
Loading