Skip to content

Commit dc48d47

Browse files
committed
fix: 初回ロード時の遅延をなくす
1 parent 124ea27 commit dc48d47

9 files changed

Lines changed: 51 additions & 19 deletions

File tree

src/components/Main/MainView/ChannelView/ChannelViewContent/ChannelViewContentMain.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:is-reached-end="isReachedEnd"
88
:is-reached-latest="isReachedLatest"
99
:is-loading="isLoading"
10+
:is-initial-load="isInitialLoad"
1011
:entry-message-id="entryMessageId"
1112
:last-loading-direction="lastLoadingDirection"
1213
@request-load-former="onLoadFormerMessagesRequest"
@@ -29,6 +30,7 @@
2930
:class="$style.element"
3031
:message-id="messageId"
3132
:is-archived="isArchived"
33+
:is-initial-load="isInitialLoad"
3234
:is-entry-message="messageId === entryMessageId"
3335
:pinned-user-id="messagePinnedUserMap.get(messageId)"
3436
@change-height="onChangeHeight"
@@ -85,6 +87,7 @@ const {
8587
isReachedEnd,
8688
isReachedLatest,
8789
isLoading,
90+
isInitialLoad,
8891
lastLoadingDirection,
8992
unreadSince,
9093
onLoadFormerMessagesRequest,

src/components/Main/MainView/MessageElement/MessageContents.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
:updated-at="message.updatedAt"
99
/>
1010
<div :class="$style.messageContents">
11-
<MarkdownContent v-show="!isEditing" :content="renderedContent" />
11+
<MarkdownContent
12+
v-show="!isEditing"
13+
:content="renderedContent"
14+
:defer-on-mounted="!isInitialLoad"
15+
/>
1216
<MessageEditor
1317
v-if="isEditing"
1418
:raw-content="message.content"
1519
:message-id="messageId"
1620
:channel-id="message.channelId"
1721
@finish-editing="finishEditing"
1822
/>
19-
<DeferredRender>
23+
<DeferredRender :disabled="isInitialLoad">
2024
<MessageQuoteList
2125
v-if="embeddingsState.quoteMessageIds.length > 0"
2226
:class="$style.messageEmbeddingsList"
@@ -58,6 +62,7 @@ import MessageHeader from './MessageHeader.vue'
5862
5963
const props = defineProps<{
6064
messageId: MessageId
65+
isInitialLoad?: boolean
6166
}>()
6267
6368
const { messagesMap } = useMessagesStore()

src/components/Main/MainView/MessageElement/MessageElement.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<MessageContents
2929
:class="$style.messageContents"
3030
:message-id="messageId"
31+
:is-initial-load="isInitialLoad"
3132
/>
3233
<MessageStampList
3334
:show-detail-button="isHovered || isMobile"
@@ -65,10 +66,12 @@ const props = withDefaults(
6566
pinnedUserId?: UserId
6667
isEntryMessage?: boolean
6768
isArchived?: boolean
69+
isInitialLoad?: boolean
6870
}>(),
6971
{
7072
isEntryMessage: false,
71-
isArchived: false
73+
isArchived: false,
74+
isInitialLoad: false
7275
}
7376
)
7477

src/components/Main/MainView/MessagesScroller/MessagesScroller.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<div :class="$style.container">
3-
<MessagesSkeleton v-if="!ready" :class="$style.skeleton" />
43
<div
54
ref="rootRef"
65
:class="[$style.root, !ready && $style.hidden]"
@@ -21,8 +20,7 @@
2120
v-if="!isReachedEnd"
2221
ref="topSkeletonRef"
2322
:simple="!enableProactiveLoading"
24-
instant
25-
:count="3"
23+
:count="isInitialLoad ? 10 : 3"
2624
:class="$style.edgeSkeleton"
2725
/>
2826
<MessagesScrollerSeparator
@@ -43,7 +41,7 @@
4341
reversed
4442
instant
4543
:simple="!enableProactiveLoading"
46-
:count="3"
44+
:count="isInitialLoad ? 10 : 3"
4745
:class="$style.edgeSkeleton"
4846
/>
4947
</div>
@@ -201,6 +199,7 @@ const props = withDefaults(
201199
isReachedEnd: boolean
202200
isReachedLatest: boolean
203201
isLoading?: boolean
202+
isInitialLoad?: boolean
204203
entryMessageId?: MessageId
205204
lastLoadingDirection: LoadingDirection
206205
}>(),
@@ -375,7 +374,6 @@ defineExpose({ rootRef })
375374
position: absolute;
376375
inset: 0;
377376
opacity: 1;
378-
visibility: visible;
379377
transition: opacity 0.3s ease-in;
380378
margin-bottom: 24px;
381379

src/components/Main/MainView/MessagesScroller/MessagesSkeleton.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
</template>
4444

4545
<script lang="ts" setup>
46+
import { computed } from 'vue'
47+
4648
const props = withDefaults(
4749
defineProps<{
4850
count?: number
@@ -76,7 +78,9 @@ const generateRandomMessage = () => {
7678
}
7779
}
7880
79-
const items = Array.from({ length: props.count }, generateRandomMessage)
81+
const items = computed(() =>
82+
Array.from({ length: props.count }, generateRandomMessage)
83+
)
8084
</script>
8185

8286
<style lang="scss" module>

src/components/Main/MainView/MessagesScroller/composables/useMessageScroller.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ref } from 'vue'
44

55
import type { ChangeHeightData } from '/@/components/Main/MainView/MessageElement/composables/useElementRenderObserver'
66
import type { LoadingDirection } from '/@/components/Main/MainView/MessagesScroller/composables/useMessagesFetcher'
7-
import { defer, wait } from '/@/lib/basic/timer'
7+
import { defer } from '/@/lib/basic/timer'
88
import type { MessageId } from '/@/types/entity-ids'
99

1010
const useMessageScroller = (
@@ -132,10 +132,7 @@ const useMessageScroller = (
132132

133133
state.height = newHeight
134134

135-
defer(async () => {
136-
await defer()
137-
await wait(400)
138-
135+
defer(() => {
139136
ready.value = true
140137
})
141138
}

src/components/Main/MainView/MessagesScroller/composables/useMessagesFetcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ const useMessageFetcher = (
213213

214214
const init = () => {
215215
resetRenderedContent()
216+
isInitialLoad.value = true
216217
if (props.entryMessageId) {
217218
onLoadAroundMessagesRequest(props.entryMessageId)
218219
} else {
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<template>
2-
<slot v-if="ready" />
2+
<slot v-if="disabled || ready" />
33
</template>
44

55
<script lang="ts" setup>
66
import { computedAsync } from '@vueuse/core'
77
88
import { defer } from '/@/lib/basic/timer'
99
10+
withDefaults(
11+
defineProps<{
12+
disabled?: boolean
13+
}>(),
14+
{
15+
disabled: false
16+
}
17+
)
18+
1019
const ready = computedAsync(() => defer(() => true))
1120
</script>

src/components/UI/MarkdownContent.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ import { defer } from '/@/lib/basic/timer'
1414
1515
import FoldableCodeBlock from './FoldableCodeBlock.vue'
1616
17-
const props = defineProps<{
18-
content: string
19-
}>()
17+
const props = withDefaults(
18+
defineProps<{
19+
content: string
20+
deferOnMounted?: boolean
21+
}>(),
22+
{
23+
deferOnMounted: true
24+
}
25+
)
2026
2127
const contentRef = ref<HTMLElement>()
2228
@@ -42,7 +48,13 @@ const applyFoldableCodeBlock = () => {
4248
})
4349
}
4450
45-
onMounted(() => defer(applyFoldableCodeBlock))
51+
onMounted(() => {
52+
if (props.deferOnMounted) {
53+
defer(applyFoldableCodeBlock)
54+
return
55+
}
56+
applyFoldableCodeBlock()
57+
})
4658
watch(() => props.content, applyFoldableCodeBlock, { flush: 'post' })
4759
</script>
4860

0 commit comments

Comments
 (0)