Skip to content

Commit e798465

Browse files
authored
[playground] Allow accordion tabs to open on error (#34844)
There was a bug where the other output passes (aside from the "Output" tab) were unable to open on compiler error. This PR still allows for the "Output" tab to automatically open on error, but also allows other tabs to be opened. https://github.com/user-attachments/assets/157bf5d6-c289-46fd-bafb-073c2e0ff52b
1 parent 5f2b571 commit e798465

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

compiler/apps/playground/components/AccordionWindow.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default function AccordionWindow(props: {
2222
tabsOpen: Set<string>;
2323
setTabsOpen: (newTab: Set<string>) => void;
2424
changedPasses: Set<string>;
25-
isFailure: boolean;
2625
}): React.ReactElement {
2726
return (
2827
<div className="flex-1 min-w-[550px] sm:min-w-0">
@@ -36,7 +35,6 @@ export default function AccordionWindow(props: {
3635
tabsOpen={props.tabsOpen}
3736
setTabsOpen={props.setTabsOpen}
3837
hasChanged={props.changedPasses.has(name)}
39-
isFailure={props.isFailure}
4038
/>
4139
);
4240
})}
@@ -51,7 +49,6 @@ function AccordionWindowItem({
5149
tabsOpen,
5250
setTabsOpen,
5351
hasChanged,
54-
isFailure,
5552
}: {
5653
name: string;
5754
tabs: TabsRecord;
@@ -61,7 +58,7 @@ function AccordionWindowItem({
6158
isFailure: boolean;
6259
}): React.ReactElement {
6360
const id = useId();
64-
const isShow = isFailure ? name === 'Output' : tabsOpen.has(name);
61+
const isShow = tabsOpen.has(name);
6562

6663
const transitionName = `accordion-window-item-${id}`;
6764

compiler/apps/playground/components/Editor/Output.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
useState,
2828
Suspense,
2929
unstable_ViewTransition as ViewTransition,
30+
unstable_addTransitionType as addTransitionType,
31+
startTransition,
3032
} from 'react';
3133
import AccordionWindow from '../AccordionWindow';
3234
import TabbedWindow from '../TabbedWindow';
@@ -35,6 +37,7 @@ import {BabelFileResult} from '@babel/core';
3537
import {
3638
CONFIG_PANEL_TRANSITION,
3739
TOGGLE_INTERNALS_TRANSITION,
40+
EXPAND_ACCORDION_TRANSITION,
3841
} from '../../lib/transitionTypes';
3942
import {LRUCache} from 'lru-cache';
4043

@@ -265,8 +268,22 @@ function OutputContent({store, compilerOutput}: Props): JSX.Element {
265268
* Update the active tab back to the output or errors tab when the compilation state
266269
* changes between success/failure.
267270
*/
268-
271+
const [previousOutputKind, setPreviousOutputKind] = useState(
272+
compilerOutput.kind,
273+
);
269274
const isFailure = compilerOutput.kind !== 'ok';
275+
276+
if (compilerOutput.kind !== previousOutputKind) {
277+
setPreviousOutputKind(compilerOutput.kind);
278+
if (isFailure) {
279+
startTransition(() => {
280+
addTransitionType(EXPAND_ACCORDION_TRANSITION);
281+
setTabsOpen(prev => new Set(prev).add('Output'));
282+
setActiveTab('Output');
283+
});
284+
}
285+
}
286+
270287
const changedPasses: Set<string> = new Set(['Output', 'HIR']); // Initial and final passes should always be bold
271288
let lastResult: string = '';
272289
for (const [passName, results] of compilerOutput.results) {
@@ -295,8 +312,6 @@ function OutputContent({store, compilerOutput}: Props): JSX.Element {
295312
tabs={tabs}
296313
activeTab={activeTab}
297314
onTabChange={setActiveTab}
298-
// Display the Output tab on compilation failure
299-
activeTabOverride={isFailure ? 'Output' : undefined}
300315
/>
301316
</ViewTransition>
302317
);
@@ -315,7 +330,6 @@ function OutputContent({store, compilerOutput}: Props): JSX.Element {
315330
tabsOpen={tabsOpen}
316331
tabs={tabs}
317332
changedPasses={changedPasses}
318-
isFailure={isFailure}
319333
/>
320334
</ViewTransition>
321335
);

compiler/apps/playground/components/TabbedWindow.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ export default function TabbedWindow({
1717
tabs,
1818
activeTab,
1919
onTabChange,
20-
activeTabOverride,
2120
}: {
2221
tabs: Map<string, React.ReactNode>;
2322
activeTab: string;
2423
onTabChange: (tab: string) => void;
25-
activeTabOverride?: string;
2624
}): React.ReactElement {
27-
const currentActiveTab = activeTabOverride ? activeTabOverride : activeTab;
28-
2925
const id = useId();
3026
const transitionName = `tab-highlight-${id}`;
3127

@@ -41,7 +37,7 @@ export default function TabbedWindow({
4137
<div className="flex flex-col h-full max-w-full">
4238
<div className="flex p-2 flex-shrink-0">
4339
{Array.from(tabs.keys()).map(tab => {
44-
const isActive = currentActiveTab === tab;
40+
const isActive = activeTab === tab;
4541
return (
4642
<button
4743
key={tab}
@@ -77,7 +73,7 @@ export default function TabbedWindow({
7773
})}
7874
</div>
7975
<div className="flex-1 overflow-hidden w-full h-full">
80-
{tabs.get(currentActiveTab)}
76+
{tabs.get(activeTab)}
8177
</div>
8278
</div>
8379
</div>

0 commit comments

Comments
 (0)