vike 0.4.197-commit-7d64995 → 0.4.197-commit-6410424
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/parseUrl.js +2 -10
- package/dist/esm/client/client-routing-runtime/navigate.js +3 -2
- package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +14 -0
- package/dist/esm/client/client-routing-runtime/prefetch.js +14 -6
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/parseUrl.d.ts +2 -2
- package/dist/esm/utils/parseUrl.js +2 -10
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -7,12 +7,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.parseUrl = parseUrl;
|
|
10
|
-
exports.assertUsageUrlPathname = assertUsageUrlPathname;
|
|
11
10
|
exports.assertUsageUrlPathnameAbsolute = assertUsageUrlPathnameAbsolute;
|
|
12
11
|
exports.assertUsageUrlRedirectTarget = assertUsageUrlRedirectTarget;
|
|
13
12
|
exports.isUrl = isUrl;
|
|
14
13
|
exports.isUri = isUri;
|
|
15
14
|
exports.isUrlRedirectTarget = isUrlRedirectTarget;
|
|
15
|
+
exports.isUrlPathnameRelative = isUrlPathnameRelative;
|
|
16
16
|
exports.isUrlExternal = isUrlExternal;
|
|
17
17
|
exports.isBaseServer = isBaseServer;
|
|
18
18
|
exports.assertUrlComponents = assertUrlComponents;
|
|
@@ -297,16 +297,13 @@ function isUri(uri) {
|
|
|
297
297
|
const { protocol } = parseProtocol(uri);
|
|
298
298
|
return !!protocol && !isUrlProtocol(uri);
|
|
299
299
|
}
|
|
300
|
-
function assertUsageUrlPathname(url, errPrefix) {
|
|
301
|
-
assertUsageUrl(url, errPrefix, { allowRelative: true });
|
|
302
|
-
}
|
|
303
300
|
function assertUsageUrlPathnameAbsolute(url, errPrefix) {
|
|
304
301
|
assertUsageUrl(url, errPrefix);
|
|
305
302
|
}
|
|
306
303
|
function assertUsageUrlRedirectTarget(url, errPrefix, isUnresolved) {
|
|
307
304
|
assertUsageUrl(url, errPrefix, { isRedirectTarget: isUnresolved ? 'unresolved' : true });
|
|
308
305
|
}
|
|
309
|
-
function assertUsageUrl(url, errPrefix, {
|
|
306
|
+
function assertUsageUrl(url, errPrefix, { isRedirectTarget } = {}) {
|
|
310
307
|
if (url.startsWith('/'))
|
|
311
308
|
return;
|
|
312
309
|
let errMsg = `${errPrefix} is ${picocolors_1.default.string(url)} but it should start with ${picocolors_1.default.string('/')}`;
|
|
@@ -320,10 +317,5 @@ function assertUsageUrl(url, errPrefix, { allowRelative, isRedirectTarget } = {}
|
|
|
320
317
|
errMsg += `, or be ${picocolors_1.default.string('*')}`;
|
|
321
318
|
}
|
|
322
319
|
}
|
|
323
|
-
if (allowRelative) {
|
|
324
|
-
if (isUrlPathnameRelative(url))
|
|
325
|
-
return;
|
|
326
|
-
errMsg += ', or be a relative URL';
|
|
327
|
-
}
|
|
328
320
|
(0, assert_js_1.assertUsage)(false, errMsg);
|
|
329
321
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { navigate };
|
|
2
2
|
export { reload };
|
|
3
|
+
import { normalizeUrlArgument } from './normalizeUrlArgument.js';
|
|
3
4
|
import { firstRenderStartPromise, renderPageClientSide } from './renderPageClientSide.js';
|
|
4
|
-
import { assertClientRouting,
|
|
5
|
+
import { assertClientRouting, getCurrentUrl } from './utils.js';
|
|
5
6
|
assertClientRouting();
|
|
6
7
|
/** Programmatically navigate to a new page.
|
|
7
8
|
*
|
|
@@ -12,7 +13,7 @@ assertClientRouting();
|
|
|
12
13
|
* @param overwriteLastHistoryEntry - Don't create a new entry in the browser's history, instead let the new URL replace the current URL. (This effectively removes the current URL from the browser history).
|
|
13
14
|
*/
|
|
14
15
|
async function navigate(url, { keepScrollPosition = false, overwriteLastHistoryEntry = false } = {}) {
|
|
15
|
-
|
|
16
|
+
normalizeUrlArgument(url, 'navigate');
|
|
16
17
|
// If `hydrationCanBeAborted === false` (e.g. Vue) then we can apply navigate() only after hydration is done
|
|
17
18
|
await firstRenderStartPromise;
|
|
18
19
|
const scrollTarget = { preserveScroll: keepScrollPosition };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { normalizeUrlArgument };
|
|
2
|
+
import { assertUsage, isUrl, isUrlPathnameRelative } from './utils.js';
|
|
3
|
+
function normalizeUrlArgument(url, fnName) {
|
|
4
|
+
// Succinct error message to save client-side KBs
|
|
5
|
+
const errMsg = `[${fnName}(url)] Invalid URL ${url}`;
|
|
6
|
+
assertUsage(isUrl(url), errMsg);
|
|
7
|
+
if (url.startsWith(location.origin)) {
|
|
8
|
+
url = url.slice(location.origin.length);
|
|
9
|
+
}
|
|
10
|
+
assertUsage(url.startsWith('/') || isUrlPathnameRelative(url),
|
|
11
|
+
// `errMsg` used the original `url` value
|
|
12
|
+
errMsg);
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
@@ -5,7 +5,7 @@ export { populatePageContextPrefetchCache };
|
|
|
5
5
|
export { addLinkPrefetchHandlers };
|
|
6
6
|
export { addLinkPrefetchHandlers_watch };
|
|
7
7
|
export { addLinkPrefetchHandlers_unwatch };
|
|
8
|
-
import { assert, assertClientRouting, assertUsage,
|
|
8
|
+
import { assert, assertClientRouting, assertUsage, assertWarning, checkIfClientRouting, getGlobalObject, hasProp, objectAssign } from './utils.js';
|
|
9
9
|
import { isErrorFetchingStaticAssets, loadUserFilesClientSide } from '../shared/loadUserFilesClientSide.js';
|
|
10
10
|
import { skipLink } from './skipLink.js';
|
|
11
11
|
import { disableClientRouting } from './renderPageClientSide.js';
|
|
@@ -17,6 +17,7 @@ import { getPageContextFromServerHooks } from './getPageContextFromHooks.js';
|
|
|
17
17
|
import { getPageContextCurrent } from './getPageContextCurrent.js';
|
|
18
18
|
import { PAGE_CONTEXT_MAX_AGE_DEFAULT, getPrefetchSettings } from './prefetch/getPrefetchSettings.js';
|
|
19
19
|
import pc from '@brillout/picocolors';
|
|
20
|
+
import { normalizeUrlArgument } from './normalizeUrlArgument.js';
|
|
20
21
|
assertClientRouting();
|
|
21
22
|
const globalObject = getGlobalObject('prefetch.ts', {
|
|
22
23
|
linkPrefetchHandlerAdded: new WeakSet(),
|
|
@@ -28,7 +29,7 @@ const globalObject = getGlobalObject('prefetch.ts', {
|
|
|
28
29
|
});
|
|
29
30
|
function getPageContextPrefetched(pageContext) {
|
|
30
31
|
const prefetchSettings = getPrefetchSettings(pageContext, null);
|
|
31
|
-
// TODO/pageContext-prefetch: we need linkTag to make this condition work
|
|
32
|
+
// TODO/pageContext-prefetch: I guess we need linkTag to make this condition work
|
|
32
33
|
if (!prefetchSettings.pageContext)
|
|
33
34
|
return null;
|
|
34
35
|
const key = getCacheKey(pageContext.urlPathname);
|
|
@@ -59,13 +60,17 @@ async function prefetchPageContextFromServerHooks(pageContextLink, resultMaxAge)
|
|
|
59
60
|
const result = await getPageContextFromServerHooks(pageContextLink, false);
|
|
60
61
|
setPageContextPrefetchCache(pageContextLink, result, resultMaxAge);
|
|
61
62
|
}
|
|
62
|
-
function populatePageContextPrefetchCache(pageContext
|
|
63
|
+
function populatePageContextPrefetchCache(pageContext /*& PageContextExports*/, result) {
|
|
64
|
+
// TODO/pageContext-prefetch: replace with using pageContext.config.prerender instead. (For being able to do that: eager configs need to be accessible without have to use PageContextExports as it isn't available here.)
|
|
65
|
+
if (!isBrilloutDocpress())
|
|
66
|
+
return;
|
|
63
67
|
setPageContextPrefetchCache(pageContext, result, null);
|
|
64
68
|
}
|
|
65
69
|
function setPageContextPrefetchCache(pageContext, result, resultMaxAge) {
|
|
66
70
|
if (resultMaxAge === null)
|
|
67
71
|
resultMaxAge = getResultMaxAge();
|
|
68
72
|
const key = getCacheKey(pageContext.urlPathname);
|
|
73
|
+
assert(isBrilloutDocpress()); // Ensure this API isn't used by anyone else
|
|
69
74
|
globalObject.prefetchedPageContexts[key] = {
|
|
70
75
|
resultFetchedAt: Date.now(),
|
|
71
76
|
resultMaxAge,
|
|
@@ -92,11 +97,10 @@ async function prefetch(url, options) {
|
|
|
92
97
|
assertUsage(checkIfClientRouting(), 'prefetch() only works with Client Routing, see https://vike.dev/prefetch', {
|
|
93
98
|
showStackTrace: true
|
|
94
99
|
});
|
|
95
|
-
|
|
96
|
-
assertUsageUrlPathname(url, errPrefix);
|
|
100
|
+
url = normalizeUrlArgument(url, 'prefetch');
|
|
97
101
|
const pageContextLink = await getPageContextLink(url);
|
|
98
102
|
if (!pageContextLink?.pageId) {
|
|
99
|
-
assertWarning(false,
|
|
103
|
+
assertWarning(false, `[prefetch(url)] ${pc.string(url)} ${noRouteMatch}`, {
|
|
100
104
|
showStackTrace: true,
|
|
101
105
|
onlyOnce: false
|
|
102
106
|
});
|
|
@@ -234,3 +238,7 @@ function getCacheKey(url) {
|
|
|
234
238
|
const key = url.split('#')[0];
|
|
235
239
|
return key;
|
|
236
240
|
}
|
|
241
|
+
// TODO/pageContext-prefetch: remove
|
|
242
|
+
function isBrilloutDocpress() {
|
|
243
|
+
return '_isBrilloutDocpress' in window;
|
|
244
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.197-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.197-commit-6410424";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.197-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.197-commit-6410424';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { parseUrl };
|
|
2
|
-
export { assertUsageUrlPathname };
|
|
3
2
|
export { assertUsageUrlPathnameAbsolute };
|
|
4
3
|
export { assertUsageUrlRedirectTarget };
|
|
5
4
|
export { isUrl };
|
|
6
5
|
export { isUri };
|
|
7
6
|
export { isUrlRedirectTarget };
|
|
7
|
+
export { isUrlPathnameRelative };
|
|
8
8
|
export { isUrlExternal };
|
|
9
9
|
export { isBaseServer };
|
|
10
10
|
export { assertUrlComponents };
|
|
@@ -50,8 +50,8 @@ declare function assertUrlComponents(url: string, origin: string | null, pathnam
|
|
|
50
50
|
declare function createUrlFromComponents(origin: string | null, pathname: string, search: string | null, hash: string | null): string;
|
|
51
51
|
declare function isUrl(url: string): boolean;
|
|
52
52
|
declare function isUrlRedirectTarget(url: string): boolean;
|
|
53
|
+
declare function isUrlPathnameRelative(url: string): boolean;
|
|
53
54
|
declare function isUrlExternal(url: string): boolean;
|
|
54
55
|
declare function isUri(uri: string): boolean;
|
|
55
|
-
declare function assertUsageUrlPathname(url: string, errPrefix: string): void;
|
|
56
56
|
declare function assertUsageUrlPathnameAbsolute(url: string, errPrefix: string): void;
|
|
57
57
|
declare function assertUsageUrlRedirectTarget(url: string, errPrefix: string, isUnresolved?: true): void;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
// - It doesn't support the tauri:// protocol
|
|
4
4
|
// Unit tests at ./parseUrl.spec.ts
|
|
5
5
|
export { parseUrl };
|
|
6
|
-
export { assertUsageUrlPathname };
|
|
7
6
|
export { assertUsageUrlPathnameAbsolute };
|
|
8
7
|
export { assertUsageUrlRedirectTarget };
|
|
9
8
|
export { isUrl };
|
|
10
9
|
export { isUri };
|
|
11
10
|
export { isUrlRedirectTarget };
|
|
11
|
+
export { isUrlPathnameRelative };
|
|
12
12
|
export { isUrlExternal };
|
|
13
13
|
export { isBaseServer };
|
|
14
14
|
export { assertUrlComponents };
|
|
@@ -293,16 +293,13 @@ function isUri(uri) {
|
|
|
293
293
|
const { protocol } = parseProtocol(uri);
|
|
294
294
|
return !!protocol && !isUrlProtocol(uri);
|
|
295
295
|
}
|
|
296
|
-
function assertUsageUrlPathname(url, errPrefix) {
|
|
297
|
-
assertUsageUrl(url, errPrefix, { allowRelative: true });
|
|
298
|
-
}
|
|
299
296
|
function assertUsageUrlPathnameAbsolute(url, errPrefix) {
|
|
300
297
|
assertUsageUrl(url, errPrefix);
|
|
301
298
|
}
|
|
302
299
|
function assertUsageUrlRedirectTarget(url, errPrefix, isUnresolved) {
|
|
303
300
|
assertUsageUrl(url, errPrefix, { isRedirectTarget: isUnresolved ? 'unresolved' : true });
|
|
304
301
|
}
|
|
305
|
-
function assertUsageUrl(url, errPrefix, {
|
|
302
|
+
function assertUsageUrl(url, errPrefix, { isRedirectTarget } = {}) {
|
|
306
303
|
if (url.startsWith('/'))
|
|
307
304
|
return;
|
|
308
305
|
let errMsg = `${errPrefix} is ${pc.string(url)} but it should start with ${pc.string('/')}`;
|
|
@@ -316,10 +313,5 @@ function assertUsageUrl(url, errPrefix, { allowRelative, isRedirectTarget } = {}
|
|
|
316
313
|
errMsg += `, or be ${pc.string('*')}`;
|
|
317
314
|
}
|
|
318
315
|
}
|
|
319
|
-
if (allowRelative) {
|
|
320
|
-
if (isUrlPathnameRelative(url))
|
|
321
|
-
return;
|
|
322
|
-
errMsg += ', or be a relative URL';
|
|
323
|
-
}
|
|
324
316
|
assertUsage(false, errMsg);
|
|
325
317
|
}
|