vike 0.4.156-commit-e46716d → 0.4.156-commit-d8d55d2

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.
@@ -151,6 +151,7 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
151
151
  (0, utils_js_1.assert)(pageContextNominalPageInit);
152
152
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextNominalPageInit, 'urlOriginal', 'string'));
153
153
  const pageContextErrorPageInit = await getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPageInit, renderContext, httpRequestId);
154
+ // Handle `throw redirect()` and `throw render()` while rendering nominal page
154
155
  if ((0, abort_js_1.isAbortError)(errNominalPage)) {
155
156
  const handled = await handleAbortError(errNominalPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit);
156
157
  if (handled.pageContextReturn) {
@@ -179,6 +180,7 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
179
180
  pageContextErrorPage = await (0, renderPageAlreadyRouted_js_1.renderPageAlreadyRouted)(pageContextErrorPageInit);
180
181
  }
181
182
  catch (errErrorPage) {
183
+ // Handle `throw redirect()` and `throw render()` while rendering error page
182
184
  if ((0, abort_js_1.isAbortError)(errErrorPage)) {
183
185
  const handled = await handleAbortError(errErrorPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit);
184
186
  // throw render(abortStatusCode)
@@ -374,7 +376,9 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
374
376
  const pageContextHttpResponse = { ...pageContextInit, httpResponse };
375
377
  return pageContextHttpResponse;
376
378
  }
377
- async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit) {
379
+ async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
380
+ // handleAbortError() creates a new pageContext object and we don't merge pageContextNominalPageInit to it: we only use some pageContextNominalPageInit information.
381
+ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit) {
378
382
  (0, abort_js_1.logAbortErrorHandled)(errAbort, (0, globalContext_js_1.getGlobalContext)().isProduction, pageContextNominalPageInit);
379
383
  const pageContextAbort = errAbort._pageContextAbort;
380
384
  let pageContextSerialized;
@@ -7,7 +7,7 @@ function addUrlComputedProps(pageContext, enumerable = true) {
7
7
  (0, utils_js_1.assert)(pageContext.urlOriginal);
8
8
  if ('urlPathname' in pageContext) {
9
9
  (0, utils_js_1.assert)(typeof pageContext.urlPathname === 'string');
10
- /* If this assert() fails then it's most likely because Object.assign() was used instead of objectAssign(), i.e.:
10
+ /* If the following assert() fails then it's most likely because Object.assign() was used instead of objectAssign(), i.e.:
11
11
  ```js
12
12
  // Add property getters such as pageContext.urlPathname to pageContext
13
13
  addUrlComputedProps(pageContext)
@@ -49,8 +49,28 @@ function getUrlParsed(pageContext) {
49
49
  if (!urlHandler) {
50
50
  urlHandler = (url) => url;
51
51
  }
52
- let urlResolved = pageContext._urlRewrite ?? pageContext.urlLogical ?? pageContext.urlOriginal;
52
+ // Example of i18n app using `throw render()`:
53
+ // 1. User goes to '/fr-FR/admin'.
54
+ // 2. The first onBeforeRoute() call accesses pageContext.urlPathname (its value is '/fr-FR/admin': the pathname of pageContext.urlOriginal, since both pageContext.urlLogical and pageContext._urlRewrite are undefined) and sets pageContext.urlLogical to '/admin'.
55
+ // 3. A guard() hooks accesses pageContext.urlPathname (its value is '/admin': the pathname of pageContext.urlLogical) and calls `throw render('/fr-FR/login')`
56
+ // 4. Vike create a new pageContext object (pageContext.urlLogical is erased) and sets pageContext._urlRewrite to '/fr-FR/login'. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
57
+ // 5. The second onBeforeRoute() call accesses pageContext.urlPathname (its value is '/fr-FR/login': the pathname of pageContext._urlRewrite, since pageContext.urlLogical is undefined) and sets pageContext.urlLogical to '/login'.
58
+ // 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
59
+ // Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
60
+ let urlResolved =
61
+ // Set by onBeforeRoute()
62
+ pageContext.urlLogical ??
63
+ // Set by `throw render()`
64
+ pageContext._urlRewrite ??
65
+ // Set by renderPage()
66
+ pageContext.urlOriginal;
53
67
  urlResolved = urlHandler(urlResolved);
68
+ /*
69
+ console.log('pageContext.urlLogical', pageContext.urlLogical)
70
+ console.log('pageContext._urlRewrite', pageContext._urlRewrite)
71
+ console.log('pageContext.urlOriginal', pageContext.urlOriginal)
72
+ console.log()
73
+ //*/
54
74
  const baseServer = pageContext._baseServer;
55
75
  (0, utils_js_1.assert)(urlResolved && typeof urlResolved === 'string');
56
76
  (0, utils_js_1.assert)(baseServer.startsWith('/'));
@@ -58,7 +58,8 @@ function isDebugEnabled(flag) {
58
58
  DEBUG = process.env.DEBUG;
59
59
  }
60
60
  catch { }
61
- return DEBUG?.includes(flag) ?? false;
61
+ const isEnabled = DEBUG?.includes(flag) ?? false;
62
+ return isEnabled;
62
63
  }
63
64
  exports.isDebugEnabled = isDebugEnabled;
64
65
  function formatMsg(info, options, padding, position) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
4
  const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
5
- const PROJECT_VERSION = '0.4.156-commit-e46716d';
5
+ const PROJECT_VERSION = '0.4.156-commit-d8d55d2';
6
6
  exports.PROJECT_VERSION = PROJECT_VERSION;
7
7
  const projectInfo = {
8
8
  projectName: 'Vike',
@@ -145,6 +145,7 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
145
145
  assert(pageContextNominalPageInit);
146
146
  assert(hasProp(pageContextNominalPageInit, 'urlOriginal', 'string'));
147
147
  const pageContextErrorPageInit = await getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPageInit, renderContext, httpRequestId);
148
+ // Handle `throw redirect()` and `throw render()` while rendering nominal page
148
149
  if (isAbortError(errNominalPage)) {
149
150
  const handled = await handleAbortError(errNominalPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit);
150
151
  if (handled.pageContextReturn) {
@@ -173,6 +174,7 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
173
174
  pageContextErrorPage = await renderPageAlreadyRouted(pageContextErrorPageInit);
174
175
  }
175
176
  catch (errErrorPage) {
177
+ // Handle `throw redirect()` and `throw render()` while rendering error page
176
178
  if (isAbortError(errErrorPage)) {
177
179
  const handled = await handleAbortError(errErrorPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit);
178
180
  // throw render(abortStatusCode)
@@ -368,7 +370,9 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
368
370
  const pageContextHttpResponse = { ...pageContextInit, httpResponse };
369
371
  return pageContextHttpResponse;
370
372
  }
371
- async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit) {
373
+ async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
374
+ // handleAbortError() creates a new pageContext object and we don't merge pageContextNominalPageInit to it: we only use some pageContextNominalPageInit information.
375
+ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageInit) {
372
376
  logAbortErrorHandled(errAbort, getGlobalContext().isProduction, pageContextNominalPageInit);
373
377
  const pageContextAbort = errAbort._pageContextAbort;
374
378
  let pageContextSerialized;
@@ -6,7 +6,7 @@ function addUrlComputedProps(pageContext, enumerable = true) {
6
6
  assert(pageContext.urlOriginal);
7
7
  if ('urlPathname' in pageContext) {
8
8
  assert(typeof pageContext.urlPathname === 'string');
9
- /* If this assert() fails then it's most likely because Object.assign() was used instead of objectAssign(), i.e.:
9
+ /* If the following assert() fails then it's most likely because Object.assign() was used instead of objectAssign(), i.e.:
10
10
  ```js
11
11
  // Add property getters such as pageContext.urlPathname to pageContext
12
12
  addUrlComputedProps(pageContext)
@@ -47,8 +47,28 @@ function getUrlParsed(pageContext) {
47
47
  if (!urlHandler) {
48
48
  urlHandler = (url) => url;
49
49
  }
50
- let urlResolved = pageContext._urlRewrite ?? pageContext.urlLogical ?? pageContext.urlOriginal;
50
+ // Example of i18n app using `throw render()`:
51
+ // 1. User goes to '/fr-FR/admin'.
52
+ // 2. The first onBeforeRoute() call accesses pageContext.urlPathname (its value is '/fr-FR/admin': the pathname of pageContext.urlOriginal, since both pageContext.urlLogical and pageContext._urlRewrite are undefined) and sets pageContext.urlLogical to '/admin'.
53
+ // 3. A guard() hooks accesses pageContext.urlPathname (its value is '/admin': the pathname of pageContext.urlLogical) and calls `throw render('/fr-FR/login')`
54
+ // 4. Vike create a new pageContext object (pageContext.urlLogical is erased) and sets pageContext._urlRewrite to '/fr-FR/login'. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
55
+ // 5. The second onBeforeRoute() call accesses pageContext.urlPathname (its value is '/fr-FR/login': the pathname of pageContext._urlRewrite, since pageContext.urlLogical is undefined) and sets pageContext.urlLogical to '/login'.
56
+ // 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
57
+ // Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
58
+ let urlResolved =
59
+ // Set by onBeforeRoute()
60
+ pageContext.urlLogical ??
61
+ // Set by `throw render()`
62
+ pageContext._urlRewrite ??
63
+ // Set by renderPage()
64
+ pageContext.urlOriginal;
51
65
  urlResolved = urlHandler(urlResolved);
66
+ /*
67
+ console.log('pageContext.urlLogical', pageContext.urlLogical)
68
+ console.log('pageContext._urlRewrite', pageContext._urlRewrite)
69
+ console.log('pageContext.urlOriginal', pageContext.urlOriginal)
70
+ console.log()
71
+ //*/
52
72
  const baseServer = pageContext._baseServer;
53
73
  assert(urlResolved && typeof urlResolved === 'string');
54
74
  assert(baseServer.startsWith('/'));
@@ -56,7 +56,8 @@ function isDebugEnabled(flag) {
56
56
  DEBUG = process.env.DEBUG;
57
57
  }
58
58
  catch { }
59
- return DEBUG?.includes(flag) ?? false;
59
+ const isEnabled = DEBUG?.includes(flag) ?? false;
60
+ return isEnabled;
60
61
  }
61
62
  function formatMsg(info, options, padding, position) {
62
63
  if (info === undefined) {
@@ -1,13 +1,13 @@
1
1
  export { projectInfo };
2
2
  export type { ProjectTag };
3
3
  export { PROJECT_VERSION };
4
- declare const PROJECT_VERSION: "0.4.156-commit-e46716d";
4
+ declare const PROJECT_VERSION: "0.4.156-commit-d8d55d2";
5
5
  type PackageName = typeof projectInfo.npmPackageName;
6
6
  type ProjectVersion = typeof projectInfo.projectVersion;
7
7
  type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
8
8
  declare const projectInfo: {
9
9
  projectName: "Vike";
10
- projectVersion: "0.4.156-commit-e46716d";
10
+ projectVersion: "0.4.156-commit-d8d55d2";
11
11
  npmPackageName: "vike";
12
12
  githubRepository: "https://github.com/vikejs/vike";
13
13
  };
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
3
  import { onProjectInfo } from './assertSingleInstance.js';
4
- const PROJECT_VERSION = '0.4.156-commit-e46716d';
4
+ const PROJECT_VERSION = '0.4.156-commit-d8d55d2';
5
5
  const projectInfo = {
6
6
  projectName: 'Vike',
7
7
  projectVersion: PROJECT_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.156-commit-e46716d",
3
+ "version": "0.4.156-commit-d8d55d2",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",