Skip to content

Commit 92c5364

Browse files
committed
chore(showcase): add explaining comments
1 parent 757a704 commit 92c5364

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

apps/website/src/components/code-snippet/code-snippet.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ import { useLocation } from '@builder.io/qwik-city';
33
import { isDev } from '@builder.io/qwik/build';
44
import { Highlight } from '../highlight/highlight';
55

6-
type CodeSnippetProps = QwikIntrinsicElements['div'] & {
7-
name: string;
8-
};
6+
// The below `/src/routes/docs/**/**/snippets/*.tsx` pattern is here so that import.meta.glob works both for fluffy and headless routes.
7+
// For example:
8+
// /src/routes/docs/components/fluffy/modal/snippets/building-blocks.tsx
9+
// /src/routes/docs/components/headless/modal/snippets/building-blocks.tsx
910

1011
const rawCodeSnippets: any = import.meta.glob('/src/routes/docs/**/**/snippets/*', {
1112
as: 'raw',
1213
eager: isDev ? false : true,
1314
});
1415

16+
type CodeSnippetProps = QwikIntrinsicElements['div'] & {
17+
name: string;
18+
};
19+
1520
export const CodeSnippet = component$<CodeSnippetProps>(({ name }) => {
1621
const location = useLocation();
1722

@@ -26,8 +31,10 @@ export const CodeSnippet = component$<CodeSnippetProps>(({ name }) => {
2631
const CodeSnippet = useSignal<string>();
2732

2833
useTask$(async () => {
34+
// We need to call `await rawCodeSnippets[snippetPath]()` in development as it is `eager:false`
2935
if (isDev) {
3036
CodeSnippet.value = await rawCodeSnippets[snippetPath]();
37+
// We need to directly access the `components[componentPath]` expression in preview/production as it is `eager:true`
3138
} else {
3239
CodeSnippet.value = rawCodeSnippets[snippetPath];
3340
}

apps/website/src/components/showcase/showcase.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useLocation } from '@builder.io/qwik-city';
1313
import { isDev } from '@builder.io/qwik/build';
1414
import { Highlight } from '../highlight/highlight';
1515

16-
// The below patterns are here so that import.meta.glob works both for fluffy and headless routes.
16+
// The below `/src/routes/docs/**/**/examples/*.tsx` patterns are here so that import.meta.glob works both for fluffy and headless routes.
1717
// For example:
1818
// /src/routes/docs/components/fluffy/modal/examples/hero.tsx
1919
// /src/routes/docs/components/headless/modal/examples/hero.tsx
@@ -43,9 +43,11 @@ export const Showcase = component$<ShowcaseProps>(({ name, ...props }) => {
4343
const ComponentRaw = useSignal<string>();
4444

4545
useTask$(async () => {
46+
// We need to call `await components[componentPath]()` in development as it is `eager:false`
4647
if (isDev) {
4748
Component.value = await components[componentPath]();
4849
ComponentRaw.value = await componentsRaw[componentPath]();
50+
// We need to directly access the `components[componentPath]` expression in preview/production as it is `eager:true`
4951
} else {
5052
Component.value = components[componentPath];
5153
ComponentRaw.value = componentsRaw[componentPath];

0 commit comments

Comments
 (0)