Skip to content

Commit 8af8c68

Browse files
refactor: website toc perf (#868)
* fix: remove visible task * remove react * fix(package.json): keep packages to avoid test.cli failing for now * chore(vite.config):bring back react --------- Co-authored-by: maiieul <[email protected]>
1 parent 316b63f commit 8af8c68

File tree

6 files changed

+46
-91
lines changed

6 files changed

+46
-91
lines changed

apps/website/src/components/toc/toc.tsx

+28-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ContentHeading } from '@builder.io/qwik-city';
22
import { cn } from '@qwik-ui/utils';
3-
import { component$, useSignal, useVisibleTask$, $ } from '@builder.io/qwik';
3+
import { component$, useSignal, $, useOnWindow } from '@builder.io/qwik';
44

55
export const DashboardTableOfContents = component$(
66
({ headings }: { headings: ContentHeading[] }) => {
@@ -122,36 +122,39 @@ const RecursiveList = component$<RecursiveListProps>(
122122
);
123123

124124
const useActiveItem = (itemIds: string[]) => {
125-
const activeId = useSignal<string>('');
126-
127-
useVisibleTask$(({ cleanup }) => {
128-
const observer = new IntersectionObserver(
129-
(entries) => {
130-
entries.forEach((entry) => {
131-
if (entry.isIntersecting) {
132-
activeId.value = entry.target.id;
133-
}
134-
});
135-
},
136-
{ rootMargin: '0% 0% -85% 0%' },
137-
);
138-
139-
itemIds.forEach((id) => {
140-
const element = document.getElementById(id);
141-
if (element) {
142-
observer.observe(element);
143-
}
144-
});
125+
const activeId = useSignal<string>();
126+
127+
useOnWindow(
128+
'scroll',
129+
$(() => {
130+
const observer = new IntersectionObserver(
131+
(entries) => {
132+
entries.forEach((entry) => {
133+
if (entry.isIntersecting) {
134+
activeId.value = entry.target.id;
135+
}
136+
});
137+
},
138+
{ rootMargin: '0% 0% -85% 0%' },
139+
);
145140

146-
cleanup(() => {
147141
itemIds.forEach((id) => {
148142
const element = document.getElementById(id);
149143
if (element) {
150-
observer.unobserve(element);
144+
observer.observe(element);
151145
}
152146
});
153-
});
154-
});
147+
148+
return () => {
149+
itemIds.forEach((id) => {
150+
const element = document.getElementById(id);
151+
if (element) {
152+
observer.unobserve(element);
153+
}
154+
});
155+
};
156+
}),
157+
);
155158

156159
return activeId;
157160
};

apps/website/src/global.css

+13
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,19 @@
12641264
border-left: 1px solid var(--qwikui-slate-300);
12651265
}
12661266

1267+
.toc-scrollbar::-webkit-scrollbar-track,
1268+
.dark .toc-scrollbar::-webkit-scrollbar-track {
1269+
border-color: transparent;
1270+
}
1271+
1272+
.toc-scrollbar::-webkit-scrollbar-thumb {
1273+
background-color: transparent;
1274+
}
1275+
1276+
.toc-scrollbar:hover.toc-scrollbar::-webkit-scrollbar-thumb {
1277+
background-color: hsla(var(--foreground) / 0.15);
1278+
}
1279+
12671280
.dark *::-webkit-scrollbar-track {
12681281
background: transparent;
12691282
border-left: 1px solid var(--qwikui-slate-800);

apps/website/src/routes/docs/headless/dropdown/index.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Qwik UI | Dropdown
55
import { FeatureList } from '~/components/feature-list/feature-list';
66
import { statusByComponent } from '~/_state/component-statuses';
77

8-
<StatusBanner status={statusByComponent.headless.Select} />
8+
<StatusBanner status={statusByComponent.headless.Dropdown} />
99

1010
# Dropdown
1111

apps/website/src/routes/layout.tsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import {
1010
import { MDXProvider } from '~/_state/MDXProvider';
1111
import { components } from '~/components/mdx-components';
1212
import { DashboardTableOfContents } from '~/components/toc/toc';
13-
import { ScrollArea } from '@qwik-ui/styled';
1413
import Header from '~/components/header/header';
1514

1615
export default component$(() => {
1716
const { headings } = useContent();
18-
1917
const { menuItemsGroups } = useKitMenuItems();
2018

2119
return (
@@ -35,12 +33,10 @@ export default component$(() => {
3533
</main>
3634
</MDXProvider>
3735
<div class="mx-6 hidden w-60 min-w-48 text-sm xl:block">
38-
<div class="sticky top-16 pt-4">
39-
<ScrollArea>
40-
<div class="sticky top-16 -mt-10 h-[calc(100vh-64px)] py-12">
41-
<DashboardTableOfContents headings={headings ? headings : []} />
42-
</div>
43-
</ScrollArea>
36+
<div class={`fixed translate-y-[-20px] py-12`}>
37+
<div class="toc-scrollbar mb-4 h-[calc(100vh-64px)] overflow-auto pb-16">
38+
<DashboardTableOfContents headings={headings ? headings : []} />
39+
</div>
4440
</div>
4541
</div>
4642
</div>

packages/kit-styled/src/components/scroll-area/scroll-area-qwikified.tsx

-56
This file was deleted.

packages/kit-styled/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ export * from './components/skeleton/skeleton';
1919
export * from './components/tabs/tabs';
2020
export * from './components/textarea/textarea';
2121
export * from './components/toggle/toggle';
22-
export * from './components/scroll-area/scroll-area-qwikified';

0 commit comments

Comments
 (0)