Skip to content

Commit b35de43

Browse files
authored
fix: hide preview container when previews: false (#412)
1 parent 13b9312 commit b35de43

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
type: lesson
3+
title: Layout change all off
4+
previews: false
5+
terminal: false
6+
editor: false
7+
---
8+
9+
# Navigation test - Layout change all off
10+
11+
This page should not show previw, editor or terminal.

e2e/src/content/tutorial/tests/navigation/meta.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ lessons:
55
- page-one
66
- page-two
77
- page-three
8+
- layout-change-all-off
89
- layout-change-from
910
- layout-change-to
1011
mainCommand: ''

e2e/test/navigation.test.ts

+45-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
import { test, expect } from '@playwright/test';
1+
import { test as base, expect } from '@playwright/test';
2+
3+
const test = base.extend<{ menu: { navigate: (name: { from: string; to: string }) => Promise<void> } }>({
4+
menu: async ({ page }, use) => {
5+
async function navigate({ from, to }: { from: string; to: string }) {
6+
// navigation select can take a while to hydrate on page load, click until responsive
7+
await expect(async () => {
8+
const button = page.getByRole('button', { name: `Tests / Navigation / ${from}` });
9+
await button.click();
10+
await expect(page.locator('[data-state="open"]', { has: button })).toBeVisible({ timeout: 50 });
11+
}).toPass();
12+
13+
await page.getByRole('region', { name: 'Navigation' }).getByRole('link', { name: to }).click();
14+
15+
await expect(page.getByRole('heading', { level: 1, name: `Navigation test - ${to}` })).toBeVisible();
16+
}
17+
18+
await use({ navigate });
19+
},
20+
});
221

322
const BASE_URL = '/tests/navigation';
423

@@ -20,17 +39,10 @@ test('user can navigate between lessons using nav bar links', async ({ page }) =
2039
}
2140
});
2241

23-
test('user can navigate between lessons using breadcrumbs', async ({ page }) => {
42+
test('user can navigate between lessons using breadcrumbs', async ({ page, menu }) => {
2443
await page.goto(`${BASE_URL}/page-one`);
2544

26-
// navigation select can take a while to hydrate on page load, click until responsive
27-
await expect(async () => {
28-
const button = page.getByRole('button', { name: 'Tests / Navigation / Page one' });
29-
await button.click();
30-
await expect(page.locator('[data-state="open"]', { has: button })).toBeVisible({ timeout: 50 });
31-
}).toPass();
32-
33-
await page.getByRole('region', { name: 'Navigation' }).getByRole('link', { name: 'Page three' }).click();
45+
await menu.navigate({ from: 'Page one', to: 'Page three' });
3446

3547
await expect(page.getByRole('heading', { level: 1, name: 'Navigation test - Page three' })).toBeVisible();
3648
});
@@ -56,3 +68,26 @@ test("user should see metadata's layout changes after navigation (#318)", async
5668
useInnerText: true,
5769
});
5870
});
71+
72+
test('user should not see preview on lessons that disable it (#405)', async ({ page, menu }) => {
73+
await page.goto(`${BASE_URL}/layout-change-from`);
74+
75+
// first page should have preview visible
76+
await expect(page.getByRole('heading', { level: 1, name: 'Navigation test - Layout change from' })).toBeVisible();
77+
78+
const preview = page.frameLocator('[title="Custom preview"]');
79+
await expect(preview.getByText('Index page')).toBeVisible();
80+
81+
await menu.navigate({ from: 'Layout change from', to: 'Layout change all off' });
82+
83+
// preview should not be visible
84+
await expect(page.locator('iframe[title="Custom preview"]')).not.toBeVisible();
85+
86+
// navigate back and check preview is visible once again
87+
await menu.navigate({ from: 'Layout change all off', to: 'Layout change from' });
88+
89+
{
90+
const preview = page.frameLocator('[title="Custom preview"]');
91+
await expect(preview.getByText('Index page')).toBeVisible();
92+
}
93+
});

packages/astro/src/default/pages/[...slug].astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ meta.description ??= 'A TutorialKit interactive lesson';
2424

2525
<Layout title={title} meta={meta}>
2626
<PageLoadingIndicator />
27-
<div id="previews-container"></div>
27+
<div id="previews-container" style="display: none;"></div>
2828
<main class="max-w-full flex flex-col h-full overflow-hidden" data-swap-root>
2929
<TopBarWrapper logoLink={logoLink ?? '/'} openInStackBlitz={lesson.data.openInStackBlitz} />
3030
<MainContainer lesson={lesson} navList={navList} />

packages/react/src/Panels/PreviewPanel.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ export const PreviewPanel = memo(
6262
useEffect(() => {
6363
// we update the iframes position at max fps if we have any
6464
if (hasPreviews) {
65-
return requestAnimationFrameLoop(onResize);
65+
const cancel = requestAnimationFrameLoop(onResize);
66+
67+
previewsContainer.style.display = 'block';
68+
69+
return () => {
70+
previewsContainer.style.display = 'none';
71+
cancel();
72+
};
6673
}
6774

6875
return undefined;

0 commit comments

Comments
 (0)