vike 0.4.199-commit-dc15087 → 0.4.199-commit-9b29f98

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.onPopState = exports.prefetch = exports.reload = exports.navigate = void 0;
3
+ exports.prefetch = exports.reload = exports.navigate = void 0;
4
4
  const assert_js_1 = require("../../utils/assert.js");
5
5
  // `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
6
6
  const navigate = (() => warnNoEffect('navigate'));
@@ -9,8 +9,6 @@ const reload = (() => warnNoEffect('reload'));
9
9
  exports.reload = reload;
10
10
  const prefetch = (() => warnNoEffect('prefetch'));
11
11
  exports.prefetch = prefetch;
12
- const onPopState = (() => { });
13
- exports.onPopState = onPopState;
14
12
  function warnNoEffect(caller) {
15
13
  (0, assert_js_1.assertWarning)(false, `Calling ${caller}() on the server-side has no effect`, {
16
14
  showStackTrace: true,
@@ -380,19 +380,29 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
380
380
  urlTarget = urlTargetExternal;
381
381
  }
382
382
  else {
383
- if (origin)
384
- urlTarget = (0, utils_js_1.addUrlOrigin)(urlTarget, origin);
385
- if (urlTarget === urlWithoutBase)
383
+ let originChanged = false;
384
+ if (origin) {
385
+ const urlModified = (0, utils_js_1.setUrlOrigin)(urlTarget, origin);
386
+ if (urlModified !== false) {
387
+ originChanged = true;
388
+ urlTarget = urlModified;
389
+ }
390
+ }
391
+ if (normalize(urlTarget) === normalize(urlWithoutBase))
386
392
  return null;
387
- urlTarget = (0, utils_js_1.prependBase)(urlTarget, baseServer);
393
+ if (!originChanged)
394
+ urlTarget = (0, utils_js_1.prependBase)(urlTarget, baseServer);
388
395
  (0, utils_js_1.assert)(urlTarget !== pageContextInit.urlOriginal);
389
396
  }
390
- (0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
397
+ (0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
391
398
  const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
392
399
  const pageContextHttpResponse = createPageContext(pageContextInit);
393
400
  (0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
394
401
  return pageContextHttpResponse;
395
402
  }
403
+ function normalize(url) {
404
+ return url || '/';
405
+ }
396
406
  async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
397
407
  // handleAbortError() creates a new pageContext object and we don't merge pageContextNominalPageInit to it: we only use some pageContextNominalPageInit information.
398
408
  pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit) {
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.199-commit-dc15087';
5
+ exports.PROJECT_VERSION = '0.4.199-commit-9b29f98';
@@ -6,7 +6,7 @@ exports.normalizeUrlPathname = normalizeUrlPathname;
6
6
  exports.removeBaseServer = removeBaseServer;
7
7
  exports.modifyUrlPathname = modifyUrlPathname;
8
8
  exports.removeUrlOrigin = removeUrlOrigin;
9
- exports.addUrlOrigin = addUrlOrigin;
9
+ exports.setUrlOrigin = setUrlOrigin;
10
10
  exports.getUrlPretty = getUrlPretty;
11
11
  const parseUrl_js_1 = require("./parseUrl.js");
12
12
  const assert_js_1 = require("./assert.js");
@@ -96,9 +96,10 @@ function removeUrlOrigin(url) {
96
96
  const urlModified = (0, parseUrl_js_1.createUrlFromComponents)(null, pathnameOriginal, searchOriginal, hashOriginal);
97
97
  return { urlModified, origin };
98
98
  }
99
- function addUrlOrigin(url, origin) {
99
+ function setUrlOrigin(url, origin) {
100
100
  const { origin: originCurrent, pathnameOriginal, searchOriginal, hashOriginal } = (0, parseUrl_js_1.parseUrl)(url, '/');
101
- (0, assert_js_1.assert)(originCurrent === null);
101
+ if (origin === originCurrent)
102
+ return false;
102
103
  (0, assert_js_1.assert)(origin === null || origin.startsWith('http'));
103
104
  const urlModified = (0, parseUrl_js_1.createUrlFromComponents)(origin, pathnameOriginal, searchOriginal, hashOriginal);
104
105
  return urlModified;
@@ -1,8 +1,4 @@
1
- export { pushHistoryState };
2
- export { onPopStateBegin };
3
- export { saveScrollPosition };
4
- export type { HistoryInfo };
5
- export type { ScrollPosition };
1
+ export { getHistoryState, enhanceHistoryState, pushHistoryState, type ScrollPosition, saveScrollPosition };
6
2
  type StateEnhanced = {
7
3
  timestamp: number;
8
4
  scrollPosition: null | ScrollPosition;
@@ -13,14 +9,7 @@ type ScrollPosition = {
13
9
  x: number;
14
10
  y: number;
15
11
  };
12
+ declare function enhanceHistoryState(): void;
13
+ declare function getHistoryState(): StateEnhanced;
16
14
  declare function saveScrollPosition(): void;
17
15
  declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
18
- type HistoryInfo = {
19
- url: `/${string}`;
20
- state: StateEnhanced;
21
- };
22
- declare function onPopStateBegin(): {
23
- isNewState: boolean;
24
- previous: HistoryInfo;
25
- current: HistoryInfo;
26
- };
@@ -1,9 +1,7 @@
1
- export { pushHistoryState };
2
- export { onPopStateBegin };
3
- export { saveScrollPosition };
4
- import { assert, assertUsage, getCurrentUrl, getGlobalObject, hasProp, isObject } from './utils.js';
1
+ export { getHistoryState, enhanceHistoryState, pushHistoryState, saveScrollPosition };
2
+ import { assert, assertUsage, hasProp, isObject } from './utils.js';
3
+ let initStateEnhanced;
5
4
  init();
6
- const globalObject = getGlobalObject('history.ts', { previous: getHistoryInfo() });
7
5
  // `window.history.state === null` when:
8
6
  // - The very first render
9
7
  // - Click on `<a href="#some-hash" />`
@@ -40,13 +38,11 @@ function enhance(stateNotEnhanced) {
40
38
  assert(isVikeEnhanced(stateVikeEnhanced));
41
39
  return stateVikeEnhanced;
42
40
  }
43
- function getState() {
41
+ function getStateEnhanced() {
44
42
  const state = getStateNotEnhanced();
45
- // *Every* state added to the history needs to go through Vike.
46
- // - Otherwise Vike's `popstate` listener won't work. (Because, for example, if globalObject.previous is outdated => isHashNavigation faulty => client-side navigation wrongfully skipped.)
47
- // - Therefore, we monkey patch history.pushState() and history.replaceState()
48
- // - Therefore, we assert() below that history.state has been enhanced by Vike
49
- // - If users stumble upon this assert() then make it a assertUsage()
43
+ // This assert() will most likely eventually cause issues. Let's then:
44
+ // - Replace the assert() call with enhanceHistoryState()
45
+ // - Remove the race condition buster `initStateEnhanced` as it won't be needed anymore
50
46
  assert(isVikeEnhanced(state));
51
47
  return state;
52
48
  }
@@ -54,6 +50,11 @@ function getStateNotEnhanced() {
54
50
  const state = window.history.state;
55
51
  return state;
56
52
  }
53
+ function getHistoryState() {
54
+ if (!initStateEnhanced)
55
+ enhanceHistoryState(); // avoid race condition
56
+ return getStateEnhanced();
57
+ }
57
58
  function getScrollPosition() {
58
59
  const scrollPosition = { x: window.scrollX, y: window.scrollY };
59
60
  return scrollPosition;
@@ -63,54 +64,48 @@ function getTimestamp() {
63
64
  }
64
65
  function saveScrollPosition() {
65
66
  const scrollPosition = getScrollPosition();
66
- const state = getState();
67
+ const state = getStateEnhanced();
67
68
  replaceHistoryState({ ...state, scrollPosition });
68
69
  }
69
70
  function pushHistoryState(url, overwriteLastHistoryEntry) {
70
71
  if (!overwriteLastHistoryEntry) {
71
- const state = {
72
- timestamp: getTimestamp(),
72
+ const timestamp = getTimestamp();
73
+ pushState({
74
+ timestamp,
73
75
  // I don't remember why I set it to `null`, maybe because setting it now would be too early? (Maybe there is a delay between renderPageClientSide() is finished and the browser updating the scroll position.) Anyways, it seems like autoSaveScrollPosition() is enough.
74
76
  scrollPosition: null,
75
77
  triggeredBy: 'vike',
76
78
  _isVikeEnhanced: true
77
- };
78
- // Calling the monkey patched history.pushState() (and not the orignal) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls
79
- // https://github.com/vikejs/vike/issues/1582
80
- window.history.pushState(state, '', url);
79
+ }, url);
81
80
  }
82
81
  else {
83
- replaceHistoryState(getState(), url);
82
+ replaceHistoryState(getStateEnhanced(), url);
84
83
  }
85
84
  }
86
85
  function replaceHistoryState(state, url) {
87
86
  const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
88
87
  window.history.replaceState(state, '', url_);
89
88
  }
90
- // Monkey patch:
91
- // - history.pushState()
92
- // - history.replaceState()
93
- function monkeyPatchHistoryAPI() {
94
- ;
95
- ['pushState', 'replaceState'].forEach((funcName) => {
96
- const funcOriginal = window.history[funcName].bind(window.history);
97
- window.history[funcName] = (stateOriginal = {}, ...rest) => {
98
- assertUsage(stateOriginal === undefined || stateOriginal === null || isObject(stateOriginal), `history.${funcName}(state) argument state must be an object`);
99
- const stateEnhanced = isVikeEnhanced(stateOriginal)
100
- ? stateOriginal
101
- : {
102
- _isVikeEnhanced: true,
103
- scrollPosition: getScrollPosition(),
104
- timestamp: getTimestamp(),
105
- triggeredBy: 'user',
106
- ...stateOriginal
107
- };
108
- assert(isVikeEnhanced(stateEnhanced));
109
- const ret = funcOriginal(stateEnhanced, ...rest);
110
- globalObject.previous = getHistoryInfo();
111
- return ret;
112
- };
113
- });
89
+ function pushState(state, url) {
90
+ // Vike should call window.history.pushState() (and not the orignal `pushStateOriginal()`) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls, see https://github.com/vikejs/vike/issues/1582.
91
+ window.history.pushState(state, '', url);
92
+ }
93
+ function monkeyPatchHistoryPushState() {
94
+ const pushStateOriginal = window.history.pushState.bind(window.history);
95
+ window.history.pushState = (stateOriginal = {}, ...rest) => {
96
+ assertUsage(stateOriginal === undefined || stateOriginal === null || isObject(stateOriginal), 'history.pushState(state) argument state must be an object');
97
+ const stateEnhanced = isVikeEnhanced(stateOriginal)
98
+ ? stateOriginal
99
+ : {
100
+ _isVikeEnhanced: true,
101
+ scrollPosition: getScrollPosition(),
102
+ timestamp: getTimestamp(),
103
+ triggeredBy: 'user',
104
+ ...stateOriginal
105
+ };
106
+ assert(isVikeEnhanced(stateEnhanced));
107
+ return pushStateOriginal(stateEnhanced, ...rest);
108
+ };
114
109
  }
115
110
  function isVikeEnhanced(state) {
116
111
  const yes = isObject(state) && '_isVikeEnhanced' in state;
@@ -131,20 +126,6 @@ function assertStateVikeEnhanced(state) {
131
126
  }
132
127
  function init() {
133
128
  enhanceHistoryState();
134
- monkeyPatchHistoryAPI();
135
- }
136
- function getHistoryInfo() {
137
- return {
138
- url: getCurrentUrl(),
139
- state: getState()
140
- };
141
- }
142
- function onPopStateBegin() {
143
- const { previous } = globalObject;
144
- const isNewState = window.history.state === null;
145
- if (isNewState)
146
- enhanceHistoryState();
147
- const current = getHistoryInfo();
148
- globalObject.previous = current;
149
- return { isNewState, previous, current };
129
+ initStateEnhanced = true;
130
+ monkeyPatchHistoryPushState();
150
131
  }
@@ -1,6 +1,5 @@
1
1
  export { navigate, reload } from './navigate.js';
2
2
  export { prefetch } from './prefetch.js';
3
- export { onPopState } from './initOnPopState.js';
4
3
  export { PROJECT_VERSION as version } from './utils.js';
5
4
  import type { PageContextBuiltInClientWithClientRouting } from '../../shared/types.js';
6
5
  /** @deprecated
@@ -5,5 +5,4 @@
5
5
  // Use package.json#exports to make the imports isomorphic.
6
6
  export { navigate, reload } from './navigate.js';
7
7
  export { prefetch } from './prefetch.js';
8
- export { onPopState } from './initOnPopState.js';
9
8
  export { PROJECT_VERSION as version } from './utils.js';
@@ -1,12 +1,4 @@
1
1
  export { initOnPopState };
2
- export { onPopState };
3
- import { type HistoryInfo } from './history.js';
2
+ export { updateState };
4
3
  declare function initOnPopState(): void;
5
- type Listener = (arg: {
6
- previous: HistoryInfo;
7
- }) => void | boolean;
8
- /** Control back-/forward navigation.
9
- *
10
- * https://vike.dev/onPopState
11
- */
12
- declare function onPopState(listener: Listener): void;
4
+ declare function updateState(): void;
@@ -1,10 +1,10 @@
1
1
  export { initOnPopState };
2
- export { onPopState };
3
- import { getGlobalObject } from './utils.js';
4
- import { onPopStateBegin } from './history.js';
2
+ export { updateState };
3
+ import { getCurrentUrl, getGlobalObject } from './utils.js';
4
+ import { enhanceHistoryState, getHistoryState } from './history.js';
5
5
  import { renderPageClientSide } from './renderPageClientSide.js';
6
6
  import { setScrollPosition } from './setScrollPosition.js';
7
- const globalObject = getGlobalObject('initOnPopState.ts', { listeners: [] });
7
+ const globalObject = getGlobalObject('initOnPopState.ts', { previous: getInfo() });
8
8
  function initOnPopState() {
9
9
  // - The popstate event is trigged upon:
10
10
  // - Back-/forward navigation.
@@ -16,14 +16,19 @@ function initOnPopState() {
16
16
  // - `location.hash = 'some-hash'`
17
17
  // - The `event` argument of `window.addEventListener('popstate', (event) => /*...*/)` is useless: the History API doesn't provide the previous state (the popped state), see https://stackoverflow.com/questions/48055323/is-history-state-always-the-same-as-popstate-event-state
18
18
  window.addEventListener('popstate', async () => {
19
- const { isNewState, previous, current } = onPopStateBegin();
19
+ const isNewState = window.history.state === null;
20
+ if (isNewState)
21
+ enhanceHistoryState();
22
+ const { previous } = globalObject;
23
+ const current = getInfo();
24
+ globalObject.previous = current;
20
25
  const scrollTarget = current.state.scrollPosition || undefined;
21
- const isUserPushStateNavigation = current.state.triggeredBy === 'user' || previous.state.triggeredBy === 'user';
22
- const isHashNavigation = current.url !== previous.url && removeHash(current.url) === removeHash(previous.url);
23
- // - `isNewState === true` when:
26
+ const isUserLandPushStateNavigation = current.state?.triggeredBy === 'user';
27
+ const isHashNavigation = removeHash(current.url) === removeHash(previous.url);
28
+ // - `history.state === null` when:
24
29
  // - Click on `<a href="#some-hash" />` (note that Vike's `initOnLinkClick()` handler skips hash links)
25
30
  // - `location.hash = 'some-hash'`
26
- // - `isNewState === false` when `popstate` was triggered by the user clicking on his browser's forward/backward history button.
31
+ // - `history.state !== null` when `popstate` was triggered by the user clicking on his browser's forward/backward history button.
27
32
  const isHashNavigationNew = isHashNavigation && isNewState;
28
33
  const isBackwardNavigation = !current.state.timestamp || !previous.state.timestamp ? null : current.state.timestamp < previous.state.timestamp;
29
34
  // We have to scroll ourselves because we use `window.history.scrollRestoration = 'manual'`. So far this seems to work. Alternatives in case it doesn't work:
@@ -35,7 +40,7 @@ function initOnPopState() {
35
40
  // - Alternative: we completely take over hash navigation and reproduce the browser's native behavior upon hash navigation.
36
41
  // - By using the `hashchange` event.
37
42
  // - Problem: conflict if user wants to override the browser's default behavior? E.g. for smooth scrolling, or when using hashes for saving states of some fancy animations.
38
- if (isHashNavigation) {
43
+ if (isHashNavigation && !isUserLandPushStateNavigation) {
39
44
  if (!isHashNavigationNew) {
40
45
  setScrollPosition(scrollTarget);
41
46
  }
@@ -44,27 +49,18 @@ function initOnPopState() {
44
49
  }
45
50
  return;
46
51
  }
47
- let doNotRenderIfSamePage = isUserPushStateNavigation;
48
- let abort;
49
- globalObject.listeners.forEach((listener) => {
50
- abort || (abort = listener({ previous }));
51
- });
52
- if (abort) {
53
- return;
54
- }
55
- if (abort === false) {
56
- doNotRenderIfSamePage = false;
57
- }
58
- await renderPageClientSide({ scrollTarget, isBackwardNavigation, doNotRenderIfSamePage });
52
+ await renderPageClientSide({ scrollTarget, isBackwardNavigation, isUserLandPushStateNavigation });
59
53
  });
60
54
  }
61
- /** Control back-/forward navigation.
62
- *
63
- * https://vike.dev/onPopState
64
- */
65
- function onPopState(listener) {
66
- globalObject.listeners.push(listener);
55
+ function getInfo() {
56
+ return {
57
+ url: getCurrentUrl(),
58
+ state: getHistoryState()
59
+ };
67
60
  }
68
61
  function removeHash(url) {
69
62
  return url.split('#')[0];
70
63
  }
64
+ function updateState() {
65
+ globalObject.previous = getInfo();
66
+ }
@@ -12,7 +12,8 @@ type RenderArgs = {
12
12
  overwriteLastHistoryEntry?: boolean;
13
13
  pageContextsFromRewrite?: PageContextFromRewrite[];
14
14
  redirectCount?: number;
15
- doNotRenderIfSamePage?: boolean;
15
+ /** Whether the navigation was triggered by the user land calling `history.pushState()` */
16
+ isUserLandPushStateNavigation?: boolean;
16
17
  isClientSideNavigation?: boolean;
17
18
  };
18
19
  declare function renderPageClientSide(renderArgs: RenderArgs): Promise<void>;
@@ -15,6 +15,7 @@ import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError,
15
15
  import { route } from '../../shared/route/index.js';
16
16
  import { isClientSideRoutable } from './isClientSideRoutable.js';
17
17
  import { setScrollPosition } from './setScrollPosition.js';
18
+ import { updateState } from './initOnPopState.js';
18
19
  import { browserNativeScrollRestoration_disable, setInitialRenderIsDone } from './scrollRestoration.js';
19
20
  import { getErrorPageId } from '../../shared/error-page.js';
20
21
  import { setPageContextCurrent } from './getPageContextCurrent.js';
@@ -29,7 +30,7 @@ const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
29
30
  })());
30
31
  const { firstRenderStartPromise } = globalObject;
31
32
  async function renderPageClientSide(renderArgs) {
32
- const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, doNotRenderIfSamePage, isClientSideNavigation = true } = renderArgs;
33
+ const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, isUserLandPushStateNavigation, isClientSideNavigation = true } = renderArgs;
33
34
  let { scrollTarget } = renderArgs;
34
35
  const { previousPageContext } = globalObject;
35
36
  addLinkPrefetchHandlers_unwatch();
@@ -119,7 +120,7 @@ async function renderPageClientSide(renderArgs) {
119
120
  const isSamePage = pageContextFromRoute.pageId &&
120
121
  previousPageContext?.pageId &&
121
122
  pageContextFromRoute.pageId === previousPageContext.pageId;
122
- if (doNotRenderIfSamePage && isSamePage) {
123
+ if (isUserLandPushStateNavigation && isSamePage) {
123
124
  // Skip's Vike's rendering; let the user handle the navigation
124
125
  return;
125
126
  }
@@ -476,6 +477,7 @@ function changeUrl(url, overwriteLastHistoryEntry) {
476
477
  return;
477
478
  browserNativeScrollRestoration_disable();
478
479
  pushHistoryState(url, overwriteLastHistoryEntry);
480
+ updateState();
479
481
  }
480
482
  function handleErrorFetchingStaticAssets(err, pageContext, isFirstRender) {
481
483
  if (!isErrorFetchingStaticAssets(err)) {
@@ -1,8 +1,6 @@
1
1
  export { navigate };
2
2
  export { reload };
3
3
  export { prefetch };
4
- export { onPopState };
5
4
  declare const navigate: never;
6
5
  declare const reload: never;
7
6
  declare const prefetch: never;
8
- declare const onPopState: never;
@@ -1,13 +1,11 @@
1
1
  export { navigate };
2
2
  export { reload };
3
3
  export { prefetch };
4
- export { onPopState };
5
4
  import { assertWarning } from '../../utils/assert.js';
6
5
  // `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
7
6
  const navigate = (() => warnNoEffect('navigate'));
8
7
  const reload = (() => warnNoEffect('reload'));
9
8
  const prefetch = (() => warnNoEffect('prefetch'));
10
- const onPopState = (() => { });
11
9
  function warnNoEffect(caller) {
12
10
  assertWarning(false, `Calling ${caller}() on the server-side has no effect`, {
13
11
  showStackTrace: true,
@@ -2,7 +2,7 @@ export { renderPage };
2
2
  export { renderPage_addWrapper };
3
3
  import { getRenderContext, getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
4
4
  import { route } from '../../shared/route/index.js';
5
- import { assert, hasProp, objectAssign, isUrl, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, addUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
5
+ import { assert, hasProp, objectAssign, isUrl, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
6
6
  import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
7
7
  import { getGlobalContext, initGlobalContext_renderPage } from './globalContext.js';
8
8
  import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
@@ -374,19 +374,29 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
374
374
  urlTarget = urlTargetExternal;
375
375
  }
376
376
  else {
377
- if (origin)
378
- urlTarget = addUrlOrigin(urlTarget, origin);
379
- if (urlTarget === urlWithoutBase)
377
+ let originChanged = false;
378
+ if (origin) {
379
+ const urlModified = setUrlOrigin(urlTarget, origin);
380
+ if (urlModified !== false) {
381
+ originChanged = true;
382
+ urlTarget = urlModified;
383
+ }
384
+ }
385
+ if (normalize(urlTarget) === normalize(urlWithoutBase))
380
386
  return null;
381
- urlTarget = prependBase(urlTarget, baseServer);
387
+ if (!originChanged)
388
+ urlTarget = prependBase(urlTarget, baseServer);
382
389
  assert(urlTarget !== pageContextInit.urlOriginal);
383
390
  }
384
- logRuntimeInfo?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
391
+ logRuntimeInfo?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
385
392
  const httpResponse = createHttpResponseRedirect({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
386
393
  const pageContextHttpResponse = createPageContext(pageContextInit);
387
394
  objectAssign(pageContextHttpResponse, { httpResponse });
388
395
  return pageContextHttpResponse;
389
396
  }
397
+ function normalize(url) {
398
+ return url || '/';
399
+ }
390
400
  async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
391
401
  // handleAbortError() creates a new pageContext object and we don't merge pageContextNominalPageInit to it: we only use some pageContextNominalPageInit information.
392
402
  pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit) {
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.199-commit-dc15087";
1
+ export declare const PROJECT_VERSION: "0.4.199-commit-9b29f98";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.199-commit-dc15087';
2
+ export const PROJECT_VERSION = '0.4.199-commit-9b29f98';
@@ -4,7 +4,7 @@ export { normalizeUrlPathname };
4
4
  export { removeBaseServer };
5
5
  export { modifyUrlPathname };
6
6
  export { removeUrlOrigin };
7
- export { addUrlOrigin };
7
+ export { setUrlOrigin };
8
8
  export { getUrlPretty };
9
9
  declare function prependBase(url: string, baseServer: string): string;
10
10
  declare function removeBaseServer(url: string, baseServer: string): string;
@@ -15,5 +15,5 @@ declare function removeUrlOrigin(url: string): {
15
15
  urlModified: string;
16
16
  origin: string | null;
17
17
  };
18
- declare function addUrlOrigin(url: string, origin: string | null): string;
18
+ declare function setUrlOrigin(url: string, origin: string | null): false | string;
19
19
  declare function getUrlPretty(url: string): string;
@@ -4,7 +4,7 @@ export { normalizeUrlPathname };
4
4
  export { removeBaseServer };
5
5
  export { modifyUrlPathname };
6
6
  export { removeUrlOrigin };
7
- export { addUrlOrigin };
7
+ export { setUrlOrigin };
8
8
  export { getUrlPretty };
9
9
  import { assertUrlComponents, createUrlFromComponents, isBaseServer, parseUrl } from './parseUrl.js';
10
10
  import { assert } from './assert.js';
@@ -94,9 +94,10 @@ function removeUrlOrigin(url) {
94
94
  const urlModified = createUrlFromComponents(null, pathnameOriginal, searchOriginal, hashOriginal);
95
95
  return { urlModified, origin };
96
96
  }
97
- function addUrlOrigin(url, origin) {
97
+ function setUrlOrigin(url, origin) {
98
98
  const { origin: originCurrent, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, '/');
99
- assert(originCurrent === null);
99
+ if (origin === originCurrent)
100
+ return false;
100
101
  assert(origin === null || origin.startsWith('http'));
101
102
  const urlModified = createUrlFromComponents(origin, pathnameOriginal, searchOriginal, hashOriginal);
102
103
  return urlModified;
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.199-commit-dc15087";
3
+ projectVersion: "0.4.199-commit-9b29f98";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.199-commit-dc15087",
3
+ "version": "0.4.199-commit-9b29f98",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {