Skip to content

Commit 3748a24

Browse files
authored
Merge pull request #8101 from QwikDev/v2-merge-main
chore: merge main into v2
2 parents 60cabc9 + 3eb3ca5 commit 3748a24

File tree

13 files changed

+151
-232
lines changed

13 files changed

+151
-232
lines changed

packages/docs/src/components/router-head/router-head.tsx

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { component$ } from '@qwik.dev/core';
2-
import { useDocumentHead, useLocation } from '@qwik.dev/router';
1+
import { component$, untrack } from '@qwik.dev/core';
2+
import { DocumentHeadTags, useDocumentHead, useLocation } from '@qwik.dev/router';
33
import { Social } from './social';
4-
import { InjectThemeScript } from '../theme-toggle';
54
import { Vendor } from './vendor';
65

6+
/** The dynamic head content */
77
export const RouterHead = component$(() => {
8-
const { url } = useLocation();
98
const head = useDocumentHead();
9+
const { url } = useLocation();
10+
const href = head.frontmatter?.canonical || untrack(() => url.href);
11+
1012
const title = head.title
1113
? `${head.title} 📚 Qwik Documentation`
1214
: `Qwik - Framework reimagined for the edge`;
@@ -47,45 +49,23 @@ export const RouterHead = component$(() => {
4749
}
4850
},
4951
};
50-
5152
return (
5253
<>
53-
<title>{title}</title>
5454
<meta name="description" content={description} />
55-
<link rel="canonical" href={head.frontmatter?.canonical || url.href} />
56-
<meta name="viewport" content="width=device-width, initial-scale=1" />
57-
<meta name="apple-mobile-web-app-title" content="Qwik" />
58-
<meta name="application-name" content="Qwik" />
59-
<meta name="apple-mobile-web-app-title" content="Qwik" />
60-
<meta name="theme-color" content="#006ce9" />
61-
<meta name="color-scheme" content="dark light" />
62-
63-
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png" />
64-
<link rel="icon" href="/favicons/favicon.svg" type="image/svg+xml" />
55+
<link rel="canonical" href={href} />
6556

6657
{import.meta.env.PROD && (
6758
<>
68-
<Social title={title} description={description} href={url.href} ogImage={OGImage.URL} />
59+
<Social title={title} description={description} href={href} ogImage={OGImage.URL} />
6960
<Vendor />
7061
</>
7162
)}
7263

73-
{head.meta
64+
<DocumentHeadTags
65+
title={title}
7466
// Skip description because that was already added at the top
75-
.filter((s) => s.name !== 'description')
76-
.map((m, key) => (
77-
<meta key={key} {...m} />
78-
))}
79-
80-
{head.links.map((l, key) => (
81-
<link key={key} {...l} />
82-
))}
83-
84-
{head.styles.map((s, key) => (
85-
<style key={key} {...s.props} dangerouslySetInnerHTML={s.style} />
86-
))}
87-
88-
<InjectThemeScript />
67+
meta={head.meta.filter((s) => s.name !== 'description')}
68+
/>
8969
</>
9070
);
9171
});

packages/docs/src/repl/ui/repl-commands.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { createPlaygroundShareUrl } from './repl-share-url';
22
import type { ReplAppInput } from '../types';
33

4-
export const ReplCommands = ({
5-
input,
6-
enableCopyToPlayground,
7-
enableDownload,
8-
}: ReplCommandProps) => {
4+
export const ReplCommands = ({ input, enableCopyToPlayground }: ReplCommandProps) => {
95
return (
106
<div class="repl-commands">
117
{enableCopyToPlayground ? (

packages/docs/src/root.tsx

Lines changed: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import { component$, useContextProvider, useStore } from '@qwik.dev/core';
22
import { Insights } from '@qwik.dev/core/insights';
3-
import {
4-
RouterOutlet,
5-
ServiceWorkerRegister,
6-
useDocumentHead,
7-
useLocation,
8-
useQwikRouter,
9-
} from '@qwik.dev/router';
10-
import RealMetricsOptimization from './components/real-metrics-optimization/real-metrics-optimization';
11-
import { Social } from './components/router-head/social';
12-
import { Vendor } from './components/router-head/vendor';
3+
import { RouterOutlet, useQwikRouter } from '@qwik.dev/router';
4+
import { RouterHead } from './components/router-head/router-head';
135
import { InjectThemeScript } from './components/theme-toggle';
14-
import { BUILDER_PUBLIC_API_KEY } from './constants';
156
import { GlobalStore, type SiteStore } from './context';
7+
168
import './global.css';
179

1810
export const uwu = /*javascript*/ `
@@ -50,8 +42,6 @@ export const uwu = /*javascript*/ `
5042

5143
export default component$(() => {
5244
useQwikRouter();
53-
const head = useDocumentHead();
54-
const { url } = useLocation();
5545

5646
const store = useStore<SiteStore>({
5747
headerMenuOpen: false,
@@ -62,55 +52,11 @@ export default component$(() => {
6252

6353
useContextProvider(GlobalStore, store);
6454

65-
const title = head.title
66-
? `${head.title} 📚 Qwik Documentation`
67-
: `Qwik - Framework reimagined for the edge`;
68-
const description =
69-
head.meta.find((m) => m.name === 'description')?.content ||
70-
`No hydration, auto lazy-loading, edge-optimized, and fun 🎉!`;
71-
72-
const OGImage = {
73-
imageURL: '',
74-
ogImgTitle: '',
75-
ogImgSubTitle: '' as string | undefined,
76-
77-
get URL() {
78-
//turn the title into array with [0] -> Title [1] -> subTitle
79-
const arrayedTitle = title.split(' | ');
80-
const ogImageUrl = new URL('https://opengraphqwik.vercel.app/api/og?level=1');
81-
82-
// biggerTitle
83-
this.ogImgTitle = arrayedTitle[0];
84-
//smallerTitle
85-
this.ogImgSubTitle = arrayedTitle[1]
86-
? arrayedTitle[1].replace(' 📚 Qwik Documentation', '')
87-
: undefined;
88-
89-
//decide whether or not to show dynamic OGimage or use docs default social card
90-
if (this.ogImgSubTitle == undefined || this.ogImgTitle == undefined) {
91-
this.imageURL = new URL(`/logos/social-card.jpg`, url).href;
92-
93-
return this.imageURL;
94-
} else {
95-
ogImageUrl.searchParams.set('title', this.ogImgTitle);
96-
ogImageUrl.searchParams.set('subtitle', this.ogImgSubTitle);
97-
// ogImageUrl.searchParams.set('level', this.routeLevel.toString());
98-
99-
this.imageURL = ogImageUrl.toString();
100-
101-
return this.imageURL;
102-
}
103-
},
104-
};
105-
10655
return (
10756
<>
10857
<head>
10958
<meta charset="utf-8" />
11059

111-
<title>{title}</title>
112-
<meta name="description" content={description} />
113-
<link rel="canonical" href={head.frontmatter?.canonical || url.href} />
11460
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
11561
<meta name="apple-mobile-web-app-title" content="Qwik" />
11662
<meta name="application-name" content="Qwik" />
@@ -121,38 +67,11 @@ export default component$(() => {
12167
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png" />
12268
<link rel="icon" href="/favicons/favicon.svg" type="image/svg+xml" />
12369

124-
{import.meta.env.PROD && (
125-
<>
126-
<Social title={title} description={description} href={url.href} ogImage={OGImage.URL} />
127-
<Vendor />
128-
</>
129-
)}
130-
131-
{/* The below are tags that were collected from all the `head` exports in the current route. */}
132-
{head.meta
133-
// Skip description because that was already added at the top
134-
.filter((s) => s.name !== 'description')
135-
.map((m, key) => (
136-
<meta key={key} {...m} />
137-
))}
138-
139-
{head.links.map((l, key) => (
140-
<link key={key} {...l} />
141-
))}
142-
143-
{head.styles.map((s, key) => (
144-
<style key={key} {...s.props} dangerouslySetInnerHTML={s.style} />
145-
))}
146-
147-
{head.scripts.map((s, key) => (
148-
<script key={key} {...s.props} dangerouslySetInnerHTML={s.script} />
149-
))}
70+
<RouterHead />
15071

15172
<InjectThemeScript />
15273
<script dangerouslySetInnerHTML={uwu} />
15374

154-
<ServiceWorkerRegister />
155-
15675
<script dangerouslySetInnerHTML={`(${collectSymbols})()`} />
15776
<Insights />
15877
</head>
@@ -164,7 +83,6 @@ export default component$(() => {
16483
>
16584
{/* This renders the current route, including all Layout components. */}
16685
<RouterOutlet />
167-
<RealMetricsOptimization builderApiKey={BUILDER_PUBLIC_API_KEY} />
16886
</body>
16987
</>
17088
);

packages/docs/src/routes/api/qwik-router/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@
726726
}
727727
],
728728
"kind": "Variable",
729-
"content": "This is a wrapper around the `useQwikRouter()` hook. We recommend using the hook instead of this component.\n\n\n```typescript\nQwikRouterProvider: import(\"@qwik.dev/core\").Component<QwikRouterProps>\n```",
729+
"content": "This is a wrapper around the `useQwikRouter()` hook. We recommend using the hook instead of this component, unless you have a good reason to make your root component reactive.\n\n\n```typescript\nQwikRouterProvider: import(\"@qwik.dev/core\").Component<QwikRouterProps>\n```",
730730
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-router/src/runtime/src/qwik-router-component.tsx",
731731
"mdFile": "router.qwikrouterprovider.md"
732732
},

packages/docs/src/routes/api/qwik-router/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ Default: `true`
17961796
17971797
## QwikRouterProvider
17981798
1799-
This is a wrapper around the `useQwikRouter()` hook. We recommend using the hook instead of this component.
1799+
This is a wrapper around the `useQwikRouter()` hook. We recommend using the hook instead of this component, unless you have a good reason to make your root component reactive.
18001800
18011801
```typescript
18021802
QwikRouterProvider: import("@qwik.dev/core").Component<QwikRouterProps>;

packages/docs/src/routes/docs/(qwikrouter)/api/index.mdx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,26 @@ export default component$(() => {
356356
});
357357
```
358358

359-
> `useQwikRouter()` should only be called once, in the root of your application.
359+
> `useQwikRouter()` should only be called once, in the root of your application. If your root component is reactive, you should move the reactive part into a child component, or you can use the `<QwikRouterProvider>` component instead.
360360
361361
## `<QwikRouterProvider>`
362362

363-
The `QwikRouterProvider` component is a wrapper around the `useQwikRouter()` hook. It does not render any DOM element, not even the matched route. We recommend using the hook instead of this component.
363+
The `QwikRouterProvider` component is a wrapper around the `useQwikRouter()` hook. It does not render any DOM element, not even the matched route. We recommend using the hook instead of this component, except when your root component is reactive.
364+
365+
```tsx title="src/root.tsx"
366+
import { QwikRouterProvider, RouterOutlet } from '@qwik.dev/router';
367+
368+
export default component$(() => (
369+
<QwikRouterProvider>
370+
<head>
371+
{/* ... */}
372+
</head>
373+
<body>
374+
<RouterOutlet />
375+
</body>
376+
</QwikRouterProvider>
377+
));
378+
```
364379

365380
## `<QwikRouterMockProvider>`
366381

packages/qwik-router/src/runtime/src/contexts.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
RouteLocation,
88
RouteNavigate,
99
RoutePreventNavigate,
10-
RouteStateInternal,
1110
} from './types';
1211

1312
export const RouteStateContext =
@@ -25,8 +24,5 @@ export const RouteNavigateContext = /*#__PURE__*/ createContextId<RouteNavigate>
2524

2625
export const RouteActionContext = /*#__PURE__*/ createContextId<RouteAction>('qc-a');
2726

28-
export const RouteInternalContext =
29-
/*#__PURE__*/ createContextId<Signal<RouteStateInternal>>('qc-ir');
30-
3127
export const RoutePreventNavigateContext =
3228
/*#__PURE__*/ createContextId<RoutePreventNavigate>('qc-p');

0 commit comments

Comments
 (0)