Skip to content

Commit 6cddd5d

Browse files
author
Orta Therox
authored
Merge pull request #957 from 86/86/fix/playground-log-scrolltobottom
fix(playground): scroll to bottom does not work in Logs tab
2 parents 56b8790 + ad3d187 commit 6cddd5d

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/playground/src/sidebar/runtime.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,24 @@ function rewireLoggingToElement(
9595
const prefix = '[<span class="log-' + name + '">' + id + "</span>]: "
9696
const eleContainerLog = eleOverflowLocator()
9797
allLogs = allLogs + prefix + output + "<br>"
98-
99-
if (eleLog && eleContainerLog) {
100-
if (autoScroll) {
101-
const atBottom = eleContainerLog.scrollHeight - eleContainerLog.clientHeight <= eleContainerLog.scrollTop + 1
102-
eleLog.innerHTML = allLogs
103-
104-
if (atBottom) eleContainerLog.scrollTop = eleContainerLog.scrollHeight - eleContainerLog.clientHeight
105-
} else {
106-
eleLog.innerHTML = allLogs
107-
}
98+
eleLog.innerHTML = allLogs
99+
const scrollElement = eleContainerLog.parentElement
100+
if (autoScroll && scrollElement) {
101+
scrollToBottom(scrollElement)
108102
}
109-
110103
// @ts-ignore
111104
console["old" + name].apply(undefined, objs)
112105
}
113106
}
114107

108+
function scrollToBottom(element: Element) {
109+
const overflowHeight = element.scrollHeight - element.clientHeight
110+
const atBottom = element.scrollTop >= overflowHeight
111+
if (!atBottom) {
112+
element.scrollTop = overflowHeight
113+
}
114+
}
115+
115116
function produceOutput(args: any[]) {
116117
return args.reduce((output: any, arg: any, index) => {
117118
const isObj = typeof arg === "object"

0 commit comments

Comments
 (0)