Skip to content

Commit 8648066

Browse files
committed
chore: setup as experimental feature
1 parent f9884f3 commit 8648066

File tree

14 files changed

+336
-24
lines changed

14 files changed

+336
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@
530530
}
531531
],
532532
"kind": "Interface",
533-
"content": "```typescript\nexport interface QwikCityMockProps \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[goto?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[RouteNavigate](#routenavigate)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[params?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, string&gt;\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[url?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>",
533+
"content": "```typescript\nexport interface QwikCityMockProps \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[fallbackToMpa?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ default: boolean; }\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[goto?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[RouteNavigate](#routenavigate)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[params?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, string&gt;\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[url?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>",
534534
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/qwik-city-component.tsx",
535535
"mdFile": "qwik-city.qwikcitymockprops.md"
536536
},
@@ -572,7 +572,7 @@
572572
}
573573
],
574574
"kind": "Interface",
575-
"content": "```typescript\nexport interface QwikCityProps \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[viewTransition?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n_(Optional)_ Enable the ViewTransition API\n\nDefault: `true`\n\n\n</td></tr>\n</tbody></table>",
575+
"content": "```typescript\nexport interface QwikCityProps \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\n[fallbackToMpa?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n{ default: boolean; }\n\n\n</td><td>\n\n_(Optional)_ Whether Qwik should fallback to MPA navigation if too many bundles are queued for preloading during SPA navigation.\n\n\n</td></tr>\n<tr><td>\n\n[viewTransition?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n_(Optional)_ Enable the ViewTransition API\n\nDefault: `true`\n\n\n</td></tr>\n</tbody></table>",
576576
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-city/src/runtime/src/qwik-city-component.tsx",
577577
"mdFile": "qwik-city.qwikcityprops.md"
578578
},

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,21 @@ Description
17811781
</th></tr></thead>
17821782
<tbody><tr><td>
17831783
1784+
[fallbackToMpa?](#)
1785+
1786+
</td><td>
1787+
1788+
</td><td>
1789+
1790+
\{ default: boolean; }
1791+
1792+
</td><td>
1793+
1794+
_(Optional)_
1795+
1796+
</td></tr>
1797+
<tr><td>
1798+
17841799
[goto?](#)
17851800
17861801
</td><td>
@@ -1988,6 +2003,21 @@ Description
19882003
</th></tr></thead>
19892004
<tbody><tr><td>
19902005
2006+
[fallbackToMpa?](#)
2007+
2008+
</td><td>
2009+
2010+
</td><td>
2011+
2012+
\{ default: boolean; }
2013+
2014+
</td><td>
2015+
2016+
_(Optional)_ Whether Qwik should fallback to MPA navigation if too many bundles are queued for preloading during SPA navigation.
2017+
2018+
</td></tr>
2019+
<tr><td>
2020+
19912021
[viewTransition?](#)
19922022
19932023
</td><td>

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@
106106
"content": "```typescript\ndirname(path: string): string;\n```\n\n\n<table><thead><tr><th>\n\nParameter\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\npath\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n\n</td></tr>\n</tbody></table>\n\n**Returns:**\n\nstring",
107107
"mdFile": "qwik.path.dirname.md"
108108
},
109+
{
110+
"name": "enableFallbackToMpa",
111+
"id": "experimentalfeatures-enablefallbacktompa",
112+
"hierarchy": [
113+
{
114+
"name": "ExperimentalFeatures",
115+
"id": "experimentalfeatures-enablefallbacktompa"
116+
},
117+
{
118+
"name": "enableFallbackToMpa",
119+
"id": "experimentalfeatures-enablefallbacktompa"
120+
}
121+
],
122+
"kind": "EnumMember",
123+
"content": "",
124+
"mdFile": "qwik.experimentalfeatures.enablefallbacktompa.md"
125+
},
109126
{
110127
"name": "enableRequestRewrite",
111128
"id": "experimentalfeatures-enablerequestrewrite",
@@ -147,7 +164,7 @@
147164
}
148165
],
149166
"kind": "Enum",
150-
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nUse `__EXPERIMENTAL__.x` to check if feature `x` is enabled. It will be replaced with `true` or `false` via an exact string replacement.\n\nAdd experimental features to this enum definition.\n\n\n```typescript\nexport declare enum ExperimentalFeatures \n```\n\n\n<table><thead><tr><th>\n\nMember\n\n\n</th><th>\n\nValue\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nenableRequestRewrite\n\n\n</td><td>\n\n`\"enableRequestRewrite\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable request.rewrite()\n\n\n</td></tr>\n<tr><td>\n\nnoSPA\n\n\n</td><td>\n\n`\"noSPA\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Disable SPA navigation handler in Qwik City\n\n\n</td></tr>\n<tr><td>\n\npreventNavigate\n\n\n</td><td>\n\n`\"preventNavigate\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the usePreventNavigate hook\n\n\n</td></tr>\n<tr><td>\n\nvalibot\n\n\n</td><td>\n\n`\"valibot\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the Valibot form validation\n\n\n</td></tr>\n</tbody></table>",
167+
"content": "> This API is provided as an alpha preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.\n> \n\nUse `__EXPERIMENTAL__.x` to check if feature `x` is enabled. It will be replaced with `true` or `false` via an exact string replacement.\n\nAdd experimental features to this enum definition.\n\n\n```typescript\nexport declare enum ExperimentalFeatures \n```\n\n\n<table><thead><tr><th>\n\nMember\n\n\n</th><th>\n\nValue\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nenableFallbackToMpa\n\n\n</td><td>\n\n`\"enableFallbackToMpa\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable falling back to MPA when SPA navigation is slow, which can happen with a big page during preloading\n\n\n</td></tr>\n<tr><td>\n\nenableRequestRewrite\n\n\n</td><td>\n\n`\"enableRequestRewrite\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable request.rewrite()\n\n\n</td></tr>\n<tr><td>\n\nnoSPA\n\n\n</td><td>\n\n`\"noSPA\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Disable SPA navigation handler in Qwik City\n\n\n</td></tr>\n<tr><td>\n\npreventNavigate\n\n\n</td><td>\n\n`\"preventNavigate\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the usePreventNavigate hook\n\n\n</td></tr>\n<tr><td>\n\nvalibot\n\n\n</td><td>\n\n`\"valibot\"`\n\n\n</td><td>\n\n**_(ALPHA)_** Enable the Valibot form validation\n\n\n</td></tr>\n</tbody></table>",
151168
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/optimizer/src/plugins/plugin.ts",
152169
"mdFile": "qwik.experimentalfeatures.md"
153170
},

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ string
328328

329329
string
330330

331+
## enableFallbackToMpa
332+
331333
## enableRequestRewrite
332334

333335
## EntryStrategy
@@ -374,6 +376,19 @@ Description
374376
</th></tr></thead>
375377
<tbody><tr><td>
376378

379+
enableFallbackToMpa
380+
381+
</td><td>
382+
383+
`"enableFallbackToMpa"`
384+
385+
</td><td>
386+
387+
**_(ALPHA)_** Enable falling back to MPA when SPA navigation is slow, which can happen with a big page during preloading
388+
389+
</td></tr>
390+
<tr><td>
391+
377392
enableRequestRewrite
378393

379394
</td><td>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ export const RouteInternalContext =
2929

3030
export const RoutePreventNavigateContext =
3131
/*#__PURE__*/ createContextId<RoutePreventNavigate>('qc-p');
32+
33+
export const fallbackToMpaContext = /*#__PURE__*/ createContextId<{ default: boolean }>('qc-f');

packages/qwik-city/src/runtime/src/link-component.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
untrack,
1010
type EventHandler,
1111
type QwikVisibleEvent,
12+
useContext,
1213
} from '@builder.io/qwik';
1314
import { getClientNavPath, shouldPreload } from './utils';
1415
import { loadClientData } from './use-endpoint';
@@ -17,6 +18,7 @@ import { preloadRouteBundles } from './client-navigate';
1718
import { isDev } from '@builder.io/qwik';
1819
// @ts-expect-error we don't have types for the preloader yet
1920
import { p as preload, f as setMpaFallbackHref } from '@builder.io/qwik/preloader';
21+
import { fallbackToMpaContext } from './contexts';
2022

2123
/** @public */
2224
export const Link = component$<LinkProps>((props) => {
@@ -35,10 +37,11 @@ export const Link = component$<LinkProps>((props) => {
3537
...linkProps
3638
} = (() => props)();
3739

38-
// We need an RFC to assess whether or not we want to provide the ability to pass a number to customize the MPA fallback threshold.
39-
// This depends on how well this feature is received in real projects, but also on what the threshold is based on: number of bundles needed to be preloaded for the next route, or the size of these bundles.
40-
// In the future, we might be able to speed up SPA so much that falling back to MPA will never make sense.
41-
const fallbackToMpa = untrack(() => Boolean(fallbackToMpaProp ?? true));
40+
const defaultFallbackToMpa = useContext(fallbackToMpaContext).default;
41+
42+
const fallbackToMpa = __EXPERIMENTAL__.enableFallbackToMpa
43+
? untrack(() => Boolean(fallbackToMpaProp ?? defaultFallbackToMpa))
44+
: undefined;
4245

4346
const clientNavPath = untrack(() => getClientNavPath({ ...linkProps, reload }, loc));
4447
linkProps.href = clientNavPath || originalHref;
@@ -74,11 +77,8 @@ export const Link = component$<LinkProps>((props) => {
7477
: undefined;
7578

7679
const preventDefault = clientNavPath
77-
? sync$((event: MouseEvent, target: HTMLAnchorElement) => {
80+
? sync$((event: MouseEvent) => {
7881
if (!(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)) {
79-
if (fallbackToMpa) {
80-
setMpaFallbackHref(target.href);
81-
}
8282
event.preventDefault();
8383
}
8484
})
@@ -96,15 +96,15 @@ export const Link = component$<LinkProps>((props) => {
9696
await nav(elm.href, { forceReload: reload, replaceState, scroll });
9797
elm.removeAttribute('aria-pressed');
9898
}
99-
if (fallbackToMpa) {
100-
setMpaFallbackHref(null);
101-
}
10299
}
103100
})
104101
: undefined;
105102

106-
const handlePreload = $((_: any, elm: HTMLAnchorElement) => {
107-
const url = new URL(elm.href);
103+
const handlePreload = $((_: any, target: HTMLAnchorElement) => {
104+
if (fallbackToMpa) {
105+
setMpaFallbackHref(target.href);
106+
}
107+
const url = new URL(target.href);
108108
preloadRouteBundles(url.pathname, 1);
109109
});
110110

packages/qwik-city/src/runtime/src/qwik-city-component.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
DocumentHeadContext,
2525
RouteActionContext,
2626
RouteInternalContext,
27+
fallbackToMpaContext,
2728
RouteLocationContext,
2829
RouteNavigateContext,
2930
RoutePreventNavigateContext,
@@ -89,6 +90,12 @@ export interface QwikCityProps {
8990
* @see https://caniuse.com/mdn-api_viewtransition
9091
*/
9192
viewTransition?: boolean;
93+
94+
/**
95+
* Whether Qwik should fallback to MPA navigation if too many bundles are queued for preloading
96+
* during SPA navigation.
97+
*/
98+
fallbackToMpa?: { default: boolean };
9299
}
93100

94101
// Gets populated by registerPreventNav on the client
@@ -307,6 +314,7 @@ export const QwikCityProvider = component$<QwikCityProps>((props) => {
307314
useContextProvider(RouteActionContext, actionState);
308315
useContextProvider(RouteInternalContext, routeInternal);
309316
useContextProvider<any>(RoutePreventNavigateContext, registerPreventNav);
317+
useContextProvider(fallbackToMpaContext, props.fallbackToMpa ?? { default: false });
310318

311319
useTask$(({ track }) => {
312320
async function run() {
@@ -646,6 +654,7 @@ export interface QwikCityMockProps {
646654
url?: string;
647655
params?: Record<string, string>;
648656
goto?: RouteNavigate;
657+
fallbackToMpa?: { default: boolean };
649658
}
650659

651660
/** @public */
@@ -693,6 +702,8 @@ export const QwikCityMockProvider = component$<QwikCityMockProps>((props) => {
693702
useContextProvider(RouteStateContext, loaderState);
694703
useContextProvider(RouteActionContext, actionState);
695704
useContextProvider(RouteInternalContext, routeInternal);
705+
console.log('props.fallbackToMpa', props.fallbackToMpa?.default);
706+
useContextProvider(fallbackToMpaContext, props.fallbackToMpa ?? { default: false });
696707

697708
return <Slot />;
698709
});

packages/qwik-city/src/runtime/src/qwik-city.runtime.api.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ export const QWIK_CITY_SCROLLER = "_qCityScroller";
331331

332332
// @public (undocumented)
333333
export interface QwikCityMockProps {
334+
// (undocumented)
335+
fallbackToMpa?: {
336+
default: boolean;
337+
};
334338
// (undocumented)
335339
goto?: RouteNavigate;
336340
// (undocumented)
@@ -360,6 +364,9 @@ export interface QwikCityPlan {
360364

361365
// @public (undocumented)
362366
export interface QwikCityProps {
367+
fallbackToMpa?: {
368+
default: boolean;
369+
};
363370
viewTransition?: boolean;
364371
}
365372

packages/qwik/src/optimizer/src/plugins/plugin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const CLIENT_STRIP_CTX_NAME = [
6666
* @alpha
6767
*/
6868
export enum ExperimentalFeatures {
69+
/**
70+
* Enable falling back to MPA when SPA navigation is slow, which can happen with a big page during
71+
* preloading
72+
*/
73+
enableFallbackToMpa = 'enableFallbackToMpa',
6974
/** Enable the usePreventNavigate hook */
7075
preventNavigate = 'preventNavigate',
7176
/** Enable the Valibot form validation */

packages/qwik/src/optimizer/src/qwik.optimizer.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type EntryStrategy = InlineEntryStrategy | HoistEntryStrategy | SingleEnt
5252

5353
// @alpha
5454
export enum ExperimentalFeatures {
55+
enableFallbackToMpa = "enableFallbackToMpa",
5556
enableRequestRewrite = "enableRequestRewrite",
5657
noSPA = "noSPA",
5758
preventNavigate = "preventNavigate",

0 commit comments

Comments
 (0)