vike 0.4.179-commit-3ede699 → 0.4.179-commit-9384166

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.
@@ -46,17 +46,27 @@ function serializePageContextClientSide(pageContext) {
46
46
  let hasWarned = false;
47
47
  const propsNonSerializable = [];
48
48
  passToClient.forEach((prop) => {
49
- const propName = JSON.stringify(prop);
50
- const varName = h(`pageContext[${propName}]`);
49
+ const propName1 = (0, utils_js_1.getPropAccessNotation)(prop);
50
+ const propName2 = JSON.stringify(prop);
51
+ const varName = `pageContext${propName1}`;
51
52
  try {
52
53
  serialize(pageContext[prop], varName);
53
54
  }
54
55
  catch (err) {
55
56
  hasWarned = true;
56
57
  propsNonSerializable.push(prop);
58
+ // useConfig() wrong usage
59
+ if (prop === '_configFromHook') {
60
+ let pathString = '';
61
+ if ((0, stringify_1.isJsonSerializerError)(err)) {
62
+ pathString = err.pathString;
63
+ }
64
+ (0, utils_js_1.assertUsage)(false, `Cannot serialize config ${h(pathString)} set by useConfig(), see https://vike.dev/useConfig#serialization-error`);
65
+ }
66
+ // Non-serializable pageContext set by the user
57
67
  let msg = [
58
- `${varName} cannot be serialized and, therefore, cannot be passed to the client.`,
59
- `Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`
68
+ `${h(varName)} can't be serialized and, therefore, can't be passed to the client side.`,
69
+ `Make sure ${h(varName)} is serializable, or remove ${h(propName2)} from ${h('passToClient')}.`
60
70
  ].join(' ');
61
71
  if ((0, stringify_1.isJsonSerializerError)(err)) {
62
72
  msg = `${msg} Serialization error: ${err.messageCore}.`;
@@ -28,7 +28,7 @@ async function executeOnRenderHtmlHook(pageContext) {
28
28
  const onErrorWhileStreaming = (err) => {
29
29
  // Should the stream inject the following?
30
30
  // ```
31
- // <script>console.error("An error occurred on the server while streaming the app to HTML. Check the server logs for more information.")</script>
31
+ // <script>console.error("An error occurred on the server side while streaming the page to HTML, see server logs.")</script>
32
32
  // ```
33
33
  (0, loggerRuntime_js_1.logRuntimeError)(err, pageContext._httpRequestId);
34
34
  if (!pageContext.errorWhileRendering) {
@@ -71,3 +71,4 @@ __exportStar(require("../../utils/isArrayOfStrings.js"), exports);
71
71
  __exportStar(require("../../utils/escapeHtml.js"), exports);
72
72
  __exportStar(require("../../utils/normalizeHeaders.js"), exports);
73
73
  __exportStar(require("../../utils/isVikeReactApp.js"), exports);
74
+ __exportStar(require("../../utils/getPropAccessNotation.js"), exports);
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPropAccessNotation = void 0;
4
4
  function getPropAccessNotation(key) {
5
- return typeof key === 'string' && /^[a-z0-9\$_]+$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
5
+ return typeof key === 'string' && isKeyDotNotationCompatible(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
6
6
  }
7
7
  exports.getPropAccessNotation = getPropAccessNotation;
8
+ function isKeyDotNotationCompatible(key) {
9
+ return /^[a-z0-9\$_]+$/i.test(key);
10
+ }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const PROJECT_VERSION = '0.4.179-commit-3ede699';
4
+ const PROJECT_VERSION = '0.4.179-commit-9384166';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -221,7 +221,7 @@ async function fetchPageContextFromServer(pageContext) {
221
221
  }
222
222
  // Is there a reason for having two different properties? Can't we use only one property? I guess/think the isServerSideError property was an attempt (a bad idea really) for rendering the error page even though an error occured on the server-side (which is a bad idea because the added complexity is non-negligible while the added value is minuscule since the error page usually doesn't have any (meaningful / server-side) hooks).
223
223
  if ('serverSideError' in pageContextFromServer || isServerSideError in pageContextFromServer) {
224
- throw getProjectError(`pageContext couldn't be fetched from server: an error occurred on the server-side (see your server logs)`);
224
+ throw getProjectError(`pageContext couldn't be fetched because an error occurred on the server-side`);
225
225
  }
226
226
  assert(hasProp(pageContextFromServer, '_pageId', 'string'));
227
227
  processPageContextFromServer(pageContextFromServer);
@@ -14,7 +14,7 @@ function getPageContextProxyForUser(pageContext) {
14
14
  get(_, prop) {
15
15
  const val = pageContext[prop];
16
16
  const propName = getPropAccessNotation(prop);
17
- assertUsage(val !== notSerializable, `pageContext${propName} couldn't be serialized and, therefore, is missing on the client-side. Check the server logs for more information.`);
17
+ assertUsage(val !== notSerializable, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
18
18
  passToClientHint(pageContext, prop, propName);
19
19
  return val;
20
20
  }
@@ -1,7 +1,7 @@
1
1
  export { serializePageContextClientSide };
2
2
  export { serializePageContextAbort };
3
3
  import { stringify, isJsonSerializerError } from '@brillout/json-serializer/stringify';
4
- import { assert, assertWarning, hasProp, unique } from '../utils.js';
4
+ import { assert, assertUsage, assertWarning, getPropAccessNotation, hasProp, unique } from '../utils.js';
5
5
  import { isErrorPage } from '../../../shared/error-page.js';
6
6
  import { addIs404ToPageProps } from '../../../shared/addIs404ToPageProps.js';
7
7
  import pc from '@brillout/picocolors';
@@ -42,17 +42,27 @@ function serializePageContextClientSide(pageContext) {
42
42
  let hasWarned = false;
43
43
  const propsNonSerializable = [];
44
44
  passToClient.forEach((prop) => {
45
- const propName = JSON.stringify(prop);
46
- const varName = h(`pageContext[${propName}]`);
45
+ const propName1 = getPropAccessNotation(prop);
46
+ const propName2 = JSON.stringify(prop);
47
+ const varName = `pageContext${propName1}`;
47
48
  try {
48
49
  serialize(pageContext[prop], varName);
49
50
  }
50
51
  catch (err) {
51
52
  hasWarned = true;
52
53
  propsNonSerializable.push(prop);
54
+ // useConfig() wrong usage
55
+ if (prop === '_configFromHook') {
56
+ let pathString = '';
57
+ if (isJsonSerializerError(err)) {
58
+ pathString = err.pathString;
59
+ }
60
+ assertUsage(false, `Cannot serialize config ${h(pathString)} set by useConfig(), see https://vike.dev/useConfig#serialization-error`);
61
+ }
62
+ // Non-serializable pageContext set by the user
53
63
  let msg = [
54
- `${varName} cannot be serialized and, therefore, cannot be passed to the client.`,
55
- `Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`
64
+ `${h(varName)} can't be serialized and, therefore, can't be passed to the client side.`,
65
+ `Make sure ${h(varName)} is serializable, or remove ${h(propName2)} from ${h('passToClient')}.`
56
66
  ].join(' ');
57
67
  if (isJsonSerializerError(err)) {
58
68
  msg = `${msg} Serialization error: ${err.messageCore}.`;
@@ -23,7 +23,7 @@ async function executeOnRenderHtmlHook(pageContext) {
23
23
  const onErrorWhileStreaming = (err) => {
24
24
  // Should the stream inject the following?
25
25
  // ```
26
- // <script>console.error("An error occurred on the server while streaming the app to HTML. Check the server logs for more information.")</script>
26
+ // <script>console.error("An error occurred on the server side while streaming the page to HTML, see server logs.")</script>
27
27
  // ```
28
28
  logRuntimeError(err, pageContext._httpRequestId);
29
29
  if (!pageContext.errorWhileRendering) {
@@ -52,3 +52,4 @@ export * from '../../utils/isArrayOfStrings.js';
52
52
  export * from '../../utils/escapeHtml.js';
53
53
  export * from '../../utils/normalizeHeaders.js';
54
54
  export * from '../../utils/isVikeReactApp.js';
55
+ export * from '../../utils/getPropAccessNotation.js';
@@ -55,3 +55,4 @@ export * from '../../utils/isArrayOfStrings.js';
55
55
  export * from '../../utils/escapeHtml.js';
56
56
  export * from '../../utils/normalizeHeaders.js';
57
57
  export * from '../../utils/isVikeReactApp.js';
58
+ export * from '../../utils/getPropAccessNotation.js';
@@ -1,3 +1,6 @@
1
1
  export function getPropAccessNotation(key) {
2
- return typeof key === 'string' && /^[a-z0-9\$_]+$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
2
+ return typeof key === 'string' && isKeyDotNotationCompatible(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
3
+ }
4
+ function isKeyDotNotationCompatible(key) {
5
+ return /^[a-z0-9\$_]+$/i.test(key);
3
6
  }
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.179-commit-3ede699";
3
+ declare const PROJECT_VERSION: "0.4.179-commit-9384166";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.179-commit-3ede699";
6
+ projectVersion: "0.4.179-commit-9384166";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.179-commit-3ede699';
3
+ const PROJECT_VERSION = '0.4.179-commit-9384166';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.179-commit-3ede699",
3
+ "version": "0.4.179-commit-9384166",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@brillout/import": "^0.2.3",
17
- "@brillout/json-serializer": "^0.5.10",
17
+ "@brillout/json-serializer": "^0.5.13",
18
18
  "@brillout/picocolors": "^1.0.13",
19
19
  "@brillout/require-shim": "^0.1.2",
20
20
  "@brillout/vite-plugin-server-entry": "^0.4.5",