Skip to content

Commit 007fe55

Browse files
committed
Expand console by default
1 parent ac0985f commit 007fe55

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

beta/src/components/MDX/Sandpack/Console.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@ export const SandpackConsole = () => {
4545
}
4646
if (message.type === 'console' && message.codesandbox) {
4747
setLogs((prev) => {
48-
const messages = [...prev, ...message.log];
49-
messages.slice(Math.max(0, messages.length - MAX_MESSAGE_COUNT));
50-
51-
return messages.filter(({method}) => method === 'log');
48+
const newLogs = message.log.filter(({method}) => method === 'log');
49+
let messages = [...prev, ...newLogs];
50+
while (messages.length > MAX_MESSAGE_COUNT) {
51+
messages.shift();
52+
}
53+
return messages;
5254
});
5355
}
5456
});
5557

5658
return unsubscribe;
5759
}, [listen]);
5860

59-
const [isExpanded, setIsExpanded] = React.useState(false);
61+
const [isExpanded, setIsExpanded] = React.useState(true);
6062

6163
React.useEffect(() => {
6264
if (wrapperRef.current) {
@@ -99,7 +101,7 @@ export const SandpackConsole = () => {
99101
</div>
100102
{isExpanded && (
101103
<div className="w-full h-full border-y bg-white dark:border-gray-700 dark:bg-gray-95 min-h-[28px] console">
102-
<div className="max-h-52 h-auto overflow-auto" ref={wrapperRef}>
104+
<div className="max-h-40 h-auto overflow-auto" ref={wrapperRef}>
103105
{logs.map(({data, id, method}) => {
104106
return (
105107
<div

beta/src/pages/learn/synchronizing-with-effects.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ By default, Effects run after *every* render. Often, this is **not what you want
233233
- Sometimes, it's slow. Synchronizing with an external system is not always instant, so you might want to skip doing it unless it's necessary. For example, you don't want to reconnect to the chat server on every keystroke.
234234
- Sometimes, it's wrong. For example, you don't want to trigger a component fade-in animation on every keystroke. The animation should only play once when the component appears for the first time.
235235

236-
To demonstrate the issue, here is the previous example with a few `console.log` calls and a text input that updates the parent component's state. Open the console and notice how typing causes the Effect to re-run:
236+
To demonstrate the issue, here is the previous example with a few `console.log` calls and a text input that updates the parent component's state. Notice how typing causes the Effect to re-run:
237237

238238
<Sandpack>
239239

@@ -821,8 +821,6 @@ export default function App() {
821821
822822
</Sandpack>
823823
824-
Expand the console panel in the sandbox above.
825-
826824
You will see three logs at first: `Schedule "a" log`, `Cancel "a" log`, and `Schedule "a" log` again. Three second later there will also be a log saying `a`. As you learned earlier on this page, the extra schedule/cancel pair is because **React remounts the component once in development to verify that you've implemented cleanup well.**
827825
828826
Now edit the input to say `abc`. If you do it fast enough, you'll see `Schedule "ab" log` immediately followed by `Cancel "ab" log` and `Schedule "abc" log`. **React always cleans up the previous render's Effect before the next render's Effect.** This is why even if you type into the input fast, there is at most one timeout scheduled at a time. Edit the input a few times and watch the console to get a feel for how Effects get cleaned up.

0 commit comments

Comments
 (0)