vike 0.4.203-commit-1b14559 → 0.4.204-commit-7f41ba2
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/client/server-routing-runtime/utils.js +0 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +3 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/parseUrl.js +4 -4
- package/dist/esm/client/client-routing-runtime/history.js +3 -2
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +17 -6
- package/dist/esm/client/client-routing-runtime/navigate.js +2 -1
- package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +1 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +2 -1
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +25 -7
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/skipLink.js +19 -15
- package/dist/esm/client/client-routing-runtime/utils.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/utils.js +0 -4
- package/dist/esm/client/server-routing-runtime/getPageContext.js +2 -1
- package/dist/esm/client/server-routing-runtime/utils.d.ts +0 -1
- package/dist/esm/client/server-routing-runtime/utils.js +0 -1
- package/dist/esm/client/shared/getCurrentUrl.js +5 -0
- package/dist/esm/client/shared/normalizeClientSideUrl.d.ts +5 -0
- package/dist/esm/client/shared/normalizeClientSideUrl.js +11 -0
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +3 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +3 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +1 -1
- 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 +4 -4
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/utils/getCurrentUrl.js +0 -18
- package/dist/esm/utils/getCurrentUrl.js +0 -16
- /package/dist/esm/{utils → client/shared}/getCurrentUrl.d.ts +0 -0
|
@@ -22,7 +22,6 @@ __exportStar(require("../../utils/assert.js"), exports);
|
|
|
22
22
|
__exportStar(require("../../utils/assertSingleInstance.js"), exports);
|
|
23
23
|
__exportStar(require("../../shared/hooks/executeHook.js"), exports);
|
|
24
24
|
__exportStar(require("../../utils/checkType.js"), exports); // Only used by Server Routing (not needed for Client Routing)
|
|
25
|
-
__exportStar(require("../../utils/getCurrentUrl.js"), exports);
|
|
26
25
|
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
27
26
|
__exportStar(require("../../utils/hasProp.js"), exports);
|
|
28
27
|
__exportStar(require("../../utils/isCallable.js"), exports);
|
|
@@ -4,10 +4,12 @@ exports.getCacheControl = getCacheControl;
|
|
|
4
4
|
const helpers_js_1 = require("../../../../shared/page-configs/helpers.js");
|
|
5
5
|
const getConfigValue_js_1 = require("../../../../shared/page-configs/getConfigValue.js");
|
|
6
6
|
const defaultValue = 'no-store, max-age=0';
|
|
7
|
-
function getCacheControl(pageId, pageConfigs) {
|
|
7
|
+
function getCacheControl(pageId, pageConfigs, statusCode) {
|
|
8
8
|
// TODO/v1-release: remove
|
|
9
9
|
if (pageConfigs.length === 0)
|
|
10
10
|
return defaultValue;
|
|
11
|
+
if (statusCode > 499)
|
|
12
|
+
return defaultValue;
|
|
11
13
|
const pageConfig = (0, helpers_js_1.getPageConfig)(pageId, pageConfigs);
|
|
12
14
|
const configValue = (0, getConfigValue_js_1.getConfigValueRuntime)(pageConfig, 'cacheControl', 'string');
|
|
13
15
|
const value = configValue?.value;
|
|
@@ -30,7 +30,7 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
|
30
30
|
const earlyHints = (0, getEarlyHints_js_1.getEarlyHints)(await pageContext.__getPageAssets());
|
|
31
31
|
const headers = [];
|
|
32
32
|
(0, utils_js_1.assert)(pageContext.pageId);
|
|
33
|
-
const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._pageConfigs);
|
|
33
|
+
const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._pageConfigs, statusCode);
|
|
34
34
|
if (cacheControl) {
|
|
35
35
|
headers.push(['Cache-Control', cacheControl]);
|
|
36
36
|
}
|
|
@@ -24,9 +24,9 @@ function parseUrl(url, baseServer) {
|
|
|
24
24
|
(0, assert_js_1.assert)(isUrl(url), url);
|
|
25
25
|
(0, assert_js_1.assert)(baseServer.startsWith('/'));
|
|
26
26
|
// Hash
|
|
27
|
-
const [urlWithoutHash, ...
|
|
27
|
+
const [urlWithoutHash, ...h] = url.split('#');
|
|
28
28
|
(0, assert_js_1.assert)(urlWithoutHash !== undefined);
|
|
29
|
-
const hashOriginal = ['', ...
|
|
29
|
+
const hashOriginal = ['', ...h].join('#') || null;
|
|
30
30
|
(0, assert_js_1.assert)(hashOriginal === null || hashOriginal.startsWith('#'));
|
|
31
31
|
const hash = hashOriginal === null ? '' : decodeSafe(hashOriginal.slice(1));
|
|
32
32
|
// Search
|
|
@@ -111,14 +111,14 @@ function getPathnameAbsoluteWithBase(url, baseServer) {
|
|
|
111
111
|
const baseURI = typeof window !== 'undefined' ? window?.document?.baseURI : undefined;
|
|
112
112
|
let base;
|
|
113
113
|
if (baseURI) {
|
|
114
|
-
const baseURIPathaname = parseOrigin(baseURI.split('?')[0]).pathname;
|
|
114
|
+
const baseURIPathaname = parseOrigin(baseURI.split('?')[0].split('#')[0]).pathname;
|
|
115
115
|
base = baseURIPathaname;
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
118
|
base = baseServer;
|
|
119
119
|
}
|
|
120
120
|
const pathnameAbsoluteWithBase = resolveUrlPathnameRelative(url, base);
|
|
121
|
-
return { protocol: null, origin: null, pathnameAbsoluteWithBase
|
|
121
|
+
return { protocol: null, origin: null, pathnameAbsoluteWithBase };
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
function parseOrigin(url) {
|
|
@@ -3,7 +3,8 @@ export { onPopStateBegin };
|
|
|
3
3
|
export { saveScrollPosition };
|
|
4
4
|
export { initHistoryState };
|
|
5
5
|
export { monkeyPatchHistoryAPI };
|
|
6
|
-
import {
|
|
6
|
+
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
7
|
+
import { assert, assertUsage, getGlobalObject, hasProp, isObject } from './utils.js';
|
|
7
8
|
initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
|
|
8
9
|
const globalObject = getGlobalObject('history.ts', { previous: getHistoryInfo() });
|
|
9
10
|
// `window.history.state === null` when:
|
|
@@ -49,7 +50,7 @@ function getState() {
|
|
|
49
50
|
// - Therefore, we have to monkey patch history.pushState() and history.replaceState()
|
|
50
51
|
// - Therefore, we need the assert() below to ensure history.state has been enhanced by Vike
|
|
51
52
|
// - If users stumble upon this assert() then let's make it a assertUsage()
|
|
52
|
-
assert(isVikeEnhanced(state));
|
|
53
|
+
assert(isVikeEnhanced(state), { state });
|
|
53
54
|
return state;
|
|
54
55
|
}
|
|
55
56
|
function getStateNotEnhanced() {
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
// Code adapted from https://github.com/HenrikJoreteg/internal-nav-helper/blob/5199ec5448d0b0db7ec63cf76d88fa6cad878b7d/src/index.js#L11-L29
|
|
2
2
|
export { initOnLinkClick };
|
|
3
3
|
import { assert } from './utils.js';
|
|
4
|
-
import { skipLink } from './skipLink.js';
|
|
4
|
+
import { isSameAsCurrentUrl, skipLink } from './skipLink.js';
|
|
5
5
|
import { renderPageClientSide } from './renderPageClientSide.js';
|
|
6
|
+
import { scrollToHashOrTop } from './setScrollPosition.js';
|
|
6
7
|
function initOnLinkClick() {
|
|
7
|
-
document.addEventListener('click',
|
|
8
|
+
document.addEventListener('click', onClick);
|
|
8
9
|
}
|
|
9
|
-
async function
|
|
10
|
+
async function onClick(ev) {
|
|
10
11
|
if (!isNormalLeftClick(ev))
|
|
11
12
|
return;
|
|
12
13
|
const linkTag = findLinkTag(ev.target);
|
|
13
14
|
if (!linkTag)
|
|
14
15
|
return;
|
|
15
|
-
const
|
|
16
|
+
const href = linkTag.getAttribute('href');
|
|
17
|
+
// Workaround for Firefox bug: clicking on a hash link that doesn't change the current URL causes Firefox to erroneously set `window.history.state = null` without firing any signal that we can detect.
|
|
18
|
+
// - https://github.com/vikejs/vike/issues/1962
|
|
19
|
+
// - https://github.com/sveltejs/kit/issues/8725
|
|
20
|
+
if (href?.includes('#') && isSameAsCurrentUrl(href)) {
|
|
21
|
+
// Prevent Firefox from setting `window.history.state` to `null`
|
|
22
|
+
ev.preventDefault();
|
|
23
|
+
// Replicate the browser's native behavior
|
|
24
|
+
scrollToHashOrTop(href.split('#')[1]);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
16
27
|
if (skipLink(linkTag))
|
|
17
28
|
return;
|
|
18
|
-
assert(
|
|
29
|
+
assert(href);
|
|
19
30
|
ev.preventDefault();
|
|
20
31
|
let scrollTarget;
|
|
21
32
|
{
|
|
@@ -25,7 +36,7 @@ async function handler(ev) {
|
|
|
25
36
|
}
|
|
26
37
|
await renderPageClientSide({
|
|
27
38
|
scrollTarget,
|
|
28
|
-
urlOriginal:
|
|
39
|
+
urlOriginal: href,
|
|
29
40
|
isBackwardNavigation: false
|
|
30
41
|
});
|
|
31
42
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { navigate };
|
|
2
2
|
export { reload };
|
|
3
|
+
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
3
4
|
import { normalizeUrlArgument } from './normalizeUrlArgument.js';
|
|
4
5
|
import { firstRenderStartPromise, renderPageClientSide } from './renderPageClientSide.js';
|
|
5
|
-
import { assertClientRouting
|
|
6
|
+
import { assertClientRouting } from './utils.js';
|
|
6
7
|
assertClientRouting();
|
|
7
8
|
/** Programmatically navigate to a new page.
|
|
8
9
|
*
|
|
@@ -5,6 +5,7 @@ function normalizeUrlArgument(url, fnName) {
|
|
|
5
5
|
const errMsg = `[${fnName}(url)] Invalid URL ${url}`;
|
|
6
6
|
assertUsage(isUrl(url), errMsg);
|
|
7
7
|
if (url.startsWith(location.origin)) {
|
|
8
|
+
// Use normalizeClientSideUrl() instead?
|
|
8
9
|
url = url.slice(location.origin.length);
|
|
9
10
|
}
|
|
10
11
|
assertUsage(url.startsWith('/') || isUrlPathnameRelative(url),
|
|
@@ -2,7 +2,7 @@ export { renderPageClientSide };
|
|
|
2
2
|
export { getRenderCount };
|
|
3
3
|
export { disableClientRouting };
|
|
4
4
|
export { firstRenderStartPromise };
|
|
5
|
-
import { assert,
|
|
5
|
+
import { assert, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, executeHook, hasProp, augmentType, genPromise, isCallable } from './utils.js';
|
|
6
6
|
import { getPageContextFromClientHooks, getPageContextFromServerHooks, getPageContextFromHooks_isHydration, getPageContextFromHooks_serialized, setPageContextInitIsPassedToClient } from './getPageContextFromHooks.js';
|
|
7
7
|
import { createPageContext } from './createPageContext.js';
|
|
8
8
|
import { addLinkPrefetchHandlers, addLinkPrefetchHandlers_unwatch, addLinkPrefetchHandlers_watch, getPageContextPrefetched, populatePageContextPrefetchCache } from './prefetch.js';
|
|
@@ -19,6 +19,7 @@ import { browserNativeScrollRestoration_disable, setInitialRenderIsDone } from '
|
|
|
19
19
|
import { getErrorPageId } from '../../shared/error-page.js';
|
|
20
20
|
import { setPageContextCurrent } from './getPageContextCurrent.js';
|
|
21
21
|
import { getRouteStringParameterList } from '../../shared/route/resolveRouteString.js';
|
|
22
|
+
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
22
23
|
const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
|
|
23
24
|
const { promise: firstRenderStartPromise, resolve: firstRenderStartPromiseResolve } = genPromise();
|
|
24
25
|
return {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { setScrollPosition };
|
|
2
2
|
export { autoSaveScrollPosition };
|
|
3
|
+
export { scrollToHashOrTop };
|
|
3
4
|
export type { ScrollTarget };
|
|
4
5
|
import { type ScrollPosition } from './history.js';
|
|
5
6
|
type ScrollTarget = undefined | {
|
|
6
7
|
preserveScroll: boolean;
|
|
7
8
|
} | ScrollPosition;
|
|
8
9
|
declare function setScrollPosition(scrollTarget: ScrollTarget): void;
|
|
10
|
+
declare function scrollToHashOrTop(hash: null | string): void;
|
|
9
11
|
declare function autoSaveScrollPosition(): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { setScrollPosition };
|
|
2
2
|
export { autoSaveScrollPosition };
|
|
3
|
+
export { scrollToHashOrTop };
|
|
3
4
|
import { assert, onPageHide, sleep, throttle } from './utils.js';
|
|
4
5
|
import { saveScrollPosition } from './history.js';
|
|
5
6
|
function setScrollPosition(scrollTarget) {
|
|
@@ -10,22 +11,39 @@ function setScrollPosition(scrollTarget) {
|
|
|
10
11
|
if (scrollTarget?.preserveScroll) {
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
const hash = getUrlHash();
|
|
15
|
+
scrollToHashOrTop(hash);
|
|
14
16
|
}
|
|
15
17
|
// Replicates the browser's native behavior
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
setScroll({ x: 0, y: 0 });
|
|
18
|
+
function scrollToHashOrTop(hash) {
|
|
19
|
+
if (!hash) {
|
|
20
|
+
scrollToTop();
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
22
|
-
const
|
|
23
|
+
const id = decodeURIComponent(hash);
|
|
24
|
+
const hashTarget = document.getElementById(id) || document.getElementsByName(id)[0];
|
|
23
25
|
if (hashTarget) {
|
|
24
26
|
hashTarget.scrollIntoView();
|
|
27
|
+
// Is this standard? We just copied SvelteKit: https://github.com/sveltejs/kit/blob/94c45b9372a9ed2b80e21cdca3f235c45edaa5b0/packages/kit/src/runtime/client/client.js#L2132
|
|
28
|
+
hashTarget.focus();
|
|
29
|
+
}
|
|
30
|
+
else if (hash === 'top') {
|
|
31
|
+
scrollToTop();
|
|
25
32
|
}
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
|
-
|
|
35
|
+
function scrollToTop() {
|
|
36
|
+
setScroll({ x: 0, y: 0 });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Change the browser's scroll position, in a way that works during a repaint.
|
|
40
|
+
*
|
|
41
|
+
* I don't remember exactly why I implemented this and what I meant with "repaint"
|
|
42
|
+
* - https://github.com/vikejs/vike/commit/fd70fadb0bcea8d922f961f1c88713994e0aaf34
|
|
43
|
+
* - I guess scrolling doesn't work during a page rendering? So we have to re-scroll until the scroll position is correct?
|
|
44
|
+
* - Do other frameworks implement this? SvelteKit doesn't seem to.
|
|
45
|
+
* - Let's remove it and see if users complain?
|
|
46
|
+
*/
|
|
29
47
|
function setScroll(scrollPosition) {
|
|
30
48
|
const scroll = () => window.scrollTo(scrollPosition.x, scrollPosition.y);
|
|
31
49
|
const done = () => window.scrollX === scrollPosition.x && window.scrollY === scrollPosition.y;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export { skipLink };
|
|
2
|
+
export { isSameAsCurrentUrl };
|
|
3
|
+
import { normalizeClientSideUrl } from '../shared/normalizeClientSideUrl.js';
|
|
2
4
|
import { getBaseServer } from './getBaseServer.js';
|
|
3
5
|
import { assert, parseUrl, isBaseServer, isUrl, isUrlExternal } from './utils.js';
|
|
4
6
|
function skipLink(linkTag) {
|
|
5
|
-
const
|
|
6
|
-
return (
|
|
7
|
-
!isUrl(
|
|
8
|
-
|
|
9
|
-
isUrlExternal(
|
|
10
|
-
|
|
7
|
+
const href = linkTag.getAttribute('href');
|
|
8
|
+
return (href === null ||
|
|
9
|
+
!isUrl(href) ||
|
|
10
|
+
href === '' ||
|
|
11
|
+
isUrlExternal(href) ||
|
|
12
|
+
isSamePageHashLink(href) ||
|
|
11
13
|
isNewTabLink(linkTag) ||
|
|
12
|
-
!hasBaseServer(
|
|
14
|
+
!hasBaseServer(href) ||
|
|
13
15
|
// Purposely last because disableAutomaticLinkInterception will be removed in the next major release
|
|
14
16
|
!isVikeLink(linkTag));
|
|
15
17
|
}
|
|
@@ -29,20 +31,22 @@ function isNewTabLink(linkTag) {
|
|
|
29
31
|
const rel = linkTag.getAttribute('rel');
|
|
30
32
|
return target === '_blank' || target === '_external' || rel === 'external' || linkTag.hasAttribute('download');
|
|
31
33
|
}
|
|
32
|
-
function
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const removeHash = (url) => url.split('#')[0];
|
|
37
|
-
if (url.includes('#') && removeHash(url) === removeHash(window.location.pathname)) {
|
|
34
|
+
function isSamePageHashLink(href) {
|
|
35
|
+
if (href.includes('#') &&
|
|
36
|
+
normalizeClientSideUrl(href, { withoutHash: true }) ===
|
|
37
|
+
normalizeClientSideUrl(window.location.href, { withoutHash: true })) {
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
|
+
assert(!href.startsWith('#'));
|
|
40
41
|
return false;
|
|
41
42
|
}
|
|
42
|
-
function
|
|
43
|
+
function isSameAsCurrentUrl(href) {
|
|
44
|
+
return normalizeClientSideUrl(href) === normalizeClientSideUrl(window.location.href);
|
|
45
|
+
}
|
|
46
|
+
function hasBaseServer(href) {
|
|
43
47
|
const baseServer = getBaseServer();
|
|
44
48
|
assert(isBaseServer(baseServer));
|
|
45
|
-
const { hasBaseServer } = parseUrl(
|
|
49
|
+
const { hasBaseServer } = parseUrl(href, baseServer);
|
|
46
50
|
return hasBaseServer;
|
|
47
51
|
}
|
|
48
52
|
function isDisableAutomaticLinkInterception() {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export * from '../server-routing-runtime/utils.js';
|
|
2
1
|
export * from '../../utils/assert.js';
|
|
3
2
|
export * from '../../utils/assertSingleInstance.js';
|
|
4
3
|
export * from '../../shared/hooks/executeHook.js';
|
|
5
|
-
export * from '../../utils/getCurrentUrl.js';
|
|
6
4
|
export * from '../../utils/getGlobalObject.js';
|
|
7
5
|
export * from '../../utils/hasProp.js';
|
|
8
6
|
export * from '../../utils/isBrowser.js';
|
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
// We assume all runtime entries will load this utils.ts file
|
|
3
3
|
import { onLoad } from './onLoad.js';
|
|
4
4
|
onLoad();
|
|
5
|
-
// We load the Server Routing utils: we tolerate the tiny amount of code that is only needed by Server Routing (only 1-2 lines).
|
|
6
|
-
// We re-export some of the utils down below only to list the utils needed by Client Routing.
|
|
7
|
-
export * from '../server-routing-runtime/utils.js';
|
|
8
5
|
export * from '../../utils/assert.js';
|
|
9
6
|
export * from '../../utils/assertSingleInstance.js';
|
|
10
7
|
export * from '../../shared/hooks/executeHook.js';
|
|
11
|
-
export * from '../../utils/getCurrentUrl.js';
|
|
12
8
|
export * from '../../utils/getGlobalObject.js';
|
|
13
9
|
export * from '../../utils/hasProp.js';
|
|
14
10
|
export * from '../../utils/isBrowser.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { assertUsage, assertWarning,
|
|
1
|
+
import { assertUsage, assertWarning, objectAssign } from './utils.js';
|
|
2
2
|
import { getPageContextSerializedInHtml } from '../shared/getPageContextSerializedInHtml.js';
|
|
3
3
|
import { getPageFilesAll } from '../../shared/getPageFiles.js';
|
|
4
4
|
import { loadUserFilesClientSide } from '../shared/loadUserFilesClientSide.js';
|
|
5
|
+
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
5
6
|
export { getPageContext };
|
|
6
7
|
const urlFirst = getCurrentUrl({ withoutHash: true });
|
|
7
8
|
async function getPageContext() {
|
|
@@ -2,7 +2,6 @@ export * from '../../utils/assert.js';
|
|
|
2
2
|
export * from '../../utils/assertSingleInstance.js';
|
|
3
3
|
export * from '../../shared/hooks/executeHook.js';
|
|
4
4
|
export * from '../../utils/checkType.js';
|
|
5
|
-
export * from '../../utils/getCurrentUrl.js';
|
|
6
5
|
export * from '../../utils/getGlobalObject.js';
|
|
7
6
|
export * from '../../utils/hasProp.js';
|
|
8
7
|
export * from '../../utils/isCallable.js';
|
|
@@ -6,7 +6,6 @@ export * from '../../utils/assert.js';
|
|
|
6
6
|
export * from '../../utils/assertSingleInstance.js';
|
|
7
7
|
export * from '../../shared/hooks/executeHook.js';
|
|
8
8
|
export * from '../../utils/checkType.js'; // Only used by Server Routing (not needed for Client Routing)
|
|
9
|
-
export * from '../../utils/getCurrentUrl.js';
|
|
10
9
|
export * from '../../utils/getGlobalObject.js';
|
|
11
10
|
export * from '../../utils/hasProp.js';
|
|
12
11
|
export * from '../../utils/isCallable.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { normalizeClientSideUrl };
|
|
2
|
+
import { assert, parseUrl } from './utils.js';
|
|
3
|
+
/** Resolves relative URLs */
|
|
4
|
+
function normalizeClientSideUrl(url, options) {
|
|
5
|
+
const { searchOriginal, hashOriginal, pathname } = parseUrl(url, '/');
|
|
6
|
+
let urlCurrent = `${pathname}${searchOriginal || ''}`;
|
|
7
|
+
if (!options?.withoutHash)
|
|
8
|
+
urlCurrent += hashOriginal || '';
|
|
9
|
+
assert(urlCurrent.startsWith('/'));
|
|
10
|
+
return urlCurrent;
|
|
11
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { getCacheControl };
|
|
2
2
|
import type { PageConfigRuntime } from '../../../../shared/page-configs/PageConfig.js';
|
|
3
|
-
|
|
3
|
+
import type { HttpResponse } from '../createHttpResponse.js';
|
|
4
|
+
type StatusCode = HttpResponse['statusCode'];
|
|
5
|
+
declare function getCacheControl(pageId: string, pageConfigs: PageConfigRuntime[], statusCode: StatusCode): string;
|
|
@@ -2,10 +2,12 @@ export { getCacheControl };
|
|
|
2
2
|
import { getPageConfig } from '../../../../shared/page-configs/helpers.js';
|
|
3
3
|
import { getConfigValueRuntime } from '../../../../shared/page-configs/getConfigValue.js';
|
|
4
4
|
const defaultValue = 'no-store, max-age=0';
|
|
5
|
-
function getCacheControl(pageId, pageConfigs) {
|
|
5
|
+
function getCacheControl(pageId, pageConfigs, statusCode) {
|
|
6
6
|
// TODO/v1-release: remove
|
|
7
7
|
if (pageConfigs.length === 0)
|
|
8
8
|
return defaultValue;
|
|
9
|
+
if (statusCode > 499)
|
|
10
|
+
return defaultValue;
|
|
9
11
|
const pageConfig = getPageConfig(pageId, pageConfigs);
|
|
10
12
|
const configValue = getConfigValueRuntime(pageConfig, 'cacheControl', 'string');
|
|
11
13
|
const value = configValue?.value;
|
|
@@ -28,7 +28,7 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
|
28
28
|
const earlyHints = getEarlyHints(await pageContext.__getPageAssets());
|
|
29
29
|
const headers = [];
|
|
30
30
|
assert(pageContext.pageId);
|
|
31
|
-
const cacheControl = getCacheControl(pageContext.pageId, pageContext._pageConfigs);
|
|
31
|
+
const cacheControl = getCacheControl(pageContext.pageId, pageContext._pageConfigs, statusCode);
|
|
32
32
|
if (cacheControl) {
|
|
33
33
|
headers.push(['Cache-Control', cacheControl]);
|
|
34
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.204-commit-7f41ba2";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.204-commit-7f41ba2';
|
|
@@ -31,11 +31,11 @@ type UrlPublic = {
|
|
|
31
31
|
/** The URL search parameters array, e.g. `{ fruit: ['apple', 'orange'] }` for `https://example.com?fruit=apple&fruit=orange` **/
|
|
32
32
|
searchAll: Record<string, string[]>;
|
|
33
33
|
/** The URL search parameterer string, e.g. `?details=yes` in `https://example.com/product/42?details=yes#reviews` */
|
|
34
|
-
searchOriginal: null | string
|
|
34
|
+
searchOriginal: null | `?${string}`;
|
|
35
35
|
/** The URL hash, e.g. `reviews` in `https://example.com/product/42?details=yes#reviews` */
|
|
36
36
|
hash: string;
|
|
37
37
|
/** The URL hash string, e.g. `#reviews` in `https://example.com/product/42?details=yes#reviews` */
|
|
38
|
-
hashOriginal: null | string
|
|
38
|
+
hashOriginal: null | `#${string}`;
|
|
39
39
|
/** @deprecated */
|
|
40
40
|
hashString: null | string;
|
|
41
41
|
/** @deprecated */
|
|
@@ -20,9 +20,9 @@ function parseUrl(url, baseServer) {
|
|
|
20
20
|
assert(isUrl(url), url);
|
|
21
21
|
assert(baseServer.startsWith('/'));
|
|
22
22
|
// Hash
|
|
23
|
-
const [urlWithoutHash, ...
|
|
23
|
+
const [urlWithoutHash, ...h] = url.split('#');
|
|
24
24
|
assert(urlWithoutHash !== undefined);
|
|
25
|
-
const hashOriginal = ['', ...
|
|
25
|
+
const hashOriginal = ['', ...h].join('#') || null;
|
|
26
26
|
assert(hashOriginal === null || hashOriginal.startsWith('#'));
|
|
27
27
|
const hash = hashOriginal === null ? '' : decodeSafe(hashOriginal.slice(1));
|
|
28
28
|
// Search
|
|
@@ -107,14 +107,14 @@ function getPathnameAbsoluteWithBase(url, baseServer) {
|
|
|
107
107
|
const baseURI = typeof window !== 'undefined' ? window?.document?.baseURI : undefined;
|
|
108
108
|
let base;
|
|
109
109
|
if (baseURI) {
|
|
110
|
-
const baseURIPathaname = parseOrigin(baseURI.split('?')[0]).pathname;
|
|
110
|
+
const baseURIPathaname = parseOrigin(baseURI.split('?')[0].split('#')[0]).pathname;
|
|
111
111
|
base = baseURIPathaname;
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
114
|
base = baseServer;
|
|
115
115
|
}
|
|
116
116
|
const pathnameAbsoluteWithBase = resolveUrlPathnameRelative(url, base);
|
|
117
|
-
return { protocol: null, origin: null, pathnameAbsoluteWithBase
|
|
117
|
+
return { protocol: null, origin: null, pathnameAbsoluteWithBase };
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
function parseOrigin(url) {
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentUrl = getCurrentUrl;
|
|
4
|
-
const parseUrl_js_1 = require("./parseUrl.js");
|
|
5
|
-
const assert_js_1 = require("./assert.js");
|
|
6
|
-
function getCurrentUrl(options) {
|
|
7
|
-
const url = window.location.href;
|
|
8
|
-
const { searchOriginal, hashOriginal, pathname } = (0, parseUrl_js_1.parseUrl)(url, '/');
|
|
9
|
-
let urlCurrent;
|
|
10
|
-
if (options?.withoutHash) {
|
|
11
|
-
urlCurrent = `${pathname}${searchOriginal || ''}`;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
urlCurrent = `${pathname}${searchOriginal || ''}${hashOriginal || ''}`;
|
|
15
|
-
}
|
|
16
|
-
(0, assert_js_1.assert)(urlCurrent.startsWith('/'));
|
|
17
|
-
return urlCurrent;
|
|
18
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { getCurrentUrl };
|
|
2
|
-
import { parseUrl } from './parseUrl.js';
|
|
3
|
-
import { assert } from './assert.js';
|
|
4
|
-
function getCurrentUrl(options) {
|
|
5
|
-
const url = window.location.href;
|
|
6
|
-
const { searchOriginal, hashOriginal, pathname } = parseUrl(url, '/');
|
|
7
|
-
let urlCurrent;
|
|
8
|
-
if (options?.withoutHash) {
|
|
9
|
-
urlCurrent = `${pathname}${searchOriginal || ''}`;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
urlCurrent = `${pathname}${searchOriginal || ''}${hashOriginal || ''}`;
|
|
13
|
-
}
|
|
14
|
-
assert(urlCurrent.startsWith('/'));
|
|
15
|
-
return urlCurrent;
|
|
16
|
-
}
|
|
File without changes
|