@scalar/server-side-rendering 0.1.26 → 0.1.28
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/CHANGELOG.md +9 -0
- package/dist/ssr.d.ts.map +1 -1
- package/dist/ssr.js +41 -27
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @scalar/server-side-rendering
|
|
2
2
|
|
|
3
|
+
## 0.1.28
|
|
4
|
+
|
|
5
|
+
## 0.1.27
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#9555](https://github.com/scalar/scalar/pull/9555): Serialize the hydration config compactly instead of pretty-printed. This shrinks the inline hydration script in every server-rendered page and speeds up serialization for large configs.
|
|
10
|
+
- [#9556](https://github.com/scalar/scalar/pull/9556): Speed up the per-render check that rejects nested functions in the config. The common case (no functions) now skips building path strings for every node, while the precise error message is still produced when a nested function is found.
|
|
11
|
+
|
|
3
12
|
## 0.1.26
|
|
4
13
|
|
|
5
14
|
## 0.1.25
|
package/dist/ssr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../src/ssr.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AA+B/E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,4BAA4B,GAAG,MAAM,CAkBtF;AAqFD;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAAC,aAAa,EAAE,4BAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7G;AAcD;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,MAAM,CA2BnC;
|
|
1
|
+
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../src/ssr.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AA+B/E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,4BAA4B,GAAG,MAAM,CAkBtF;AAqFD;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAAC,aAAa,EAAE,4BAA4B,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7G;AAcD;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,MAAM,CA2BnC;AAwID;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CA2B3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,uCAAuC;IACvC,MAAM,EAAE,4BAA4B,CAAA;IACpC,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BlB"}
|
package/dist/ssr.js
CHANGED
|
@@ -203,39 +203,53 @@ function escapeFunctionSourceForInlineScript(source) {
|
|
|
203
203
|
.replace(/\u2028/g, '\\u2028')
|
|
204
204
|
.replace(/\u2029/g, '\\u2029');
|
|
205
205
|
}
|
|
206
|
-
/** Add consistent indentation to multiline strings embedded in HTML output. */
|
|
207
|
-
const addIndent = (str, spaces = 2, initialIndent = false) => {
|
|
208
|
-
const indent = ' '.repeat(spaces);
|
|
209
|
-
const lines = str.split('\n');
|
|
210
|
-
return lines
|
|
211
|
-
.map((line, index) => {
|
|
212
|
-
if (index === 0 && !initialIndent) {
|
|
213
|
-
return line;
|
|
214
|
-
}
|
|
215
|
-
return `${indent}${line}`;
|
|
216
|
-
})
|
|
217
|
-
.join('\n');
|
|
218
|
-
};
|
|
219
206
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
207
|
+
* Cheap recursive check for a function nested anywhere in a value.
|
|
208
|
+
*
|
|
209
|
+
* This runs on the full configuration for every render, so it deliberately avoids
|
|
210
|
+
* building path strings (the common case has no functions and never needs them).
|
|
223
211
|
*/
|
|
224
|
-
const
|
|
212
|
+
const containsNestedFunction = (value) => {
|
|
213
|
+
if (typeof value === 'function') {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
if (Array.isArray(value)) {
|
|
217
|
+
return value.some(containsNestedFunction);
|
|
218
|
+
}
|
|
219
|
+
if (value && typeof value === 'object') {
|
|
220
|
+
return Object.values(value).some(containsNestedFunction);
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
};
|
|
224
|
+
/** Walk the value to build the precise path of the first nested function and throw. */
|
|
225
|
+
const throwNestedFunctionError = (value, path) => {
|
|
225
226
|
if (typeof value === 'function') {
|
|
226
227
|
throw new Error(`Cannot serialize function at "${path}" for SSR hydration. ` +
|
|
227
228
|
'Only top-level function properties and top-level arrays containing functions are supported.');
|
|
228
229
|
}
|
|
229
230
|
if (Array.isArray(value)) {
|
|
230
|
-
value.forEach((item, index) =>
|
|
231
|
+
value.forEach((item, index) => throwNestedFunctionError(item, `${path}[${index}]`));
|
|
231
232
|
return;
|
|
232
233
|
}
|
|
233
234
|
if (value && typeof value === 'object') {
|
|
234
|
-
Object.entries(value).forEach(([key, nestedValue]) =>
|
|
235
|
+
Object.entries(value).forEach(([key, nestedValue]) => throwNestedFunctionError(nestedValue, `${path}.${key}`));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Reject function values that would otherwise be silently dropped by JSON.stringify.
|
|
240
|
+
* SSR only supports top-level function props and top-level arrays containing functions,
|
|
241
|
+
* matching the client-side renderer behavior.
|
|
242
|
+
*
|
|
243
|
+
* The cheap detection pass runs every render; the expensive path-building pass only
|
|
244
|
+
* runs in the rare case where a nested function is actually present.
|
|
245
|
+
*/
|
|
246
|
+
const assertNoNestedFunctions = (value, path) => {
|
|
247
|
+
if (containsNestedFunction(value)) {
|
|
248
|
+
throwNestedFunctionError(value, path);
|
|
235
249
|
}
|
|
236
250
|
};
|
|
237
251
|
const serializeJsonValue = (value) => escapeJsonForInlineScript(JSON.stringify(value));
|
|
238
|
-
const serializeJsonObject = (value) => escapeJsonForInlineScript(JSON.stringify(value
|
|
252
|
+
const serializeJsonObject = (value) => escapeJsonForInlineScript(JSON.stringify(value));
|
|
239
253
|
const serializePropertyKey = (key) => escapeJsonForInlineScript(JSON.stringify(key));
|
|
240
254
|
const serializeArrayWithFunctions = (value, path) => {
|
|
241
255
|
return `[${value
|
|
@@ -251,12 +265,13 @@ const serializeArrayWithFunctions = (value, path) => {
|
|
|
251
265
|
const serializeFunctionProperty = (key, value) => `${serializePropertyKey(key)}: ${escapeFunctionSourceForInlineScript(value.toString())}`;
|
|
252
266
|
const serializeArrayProperty = (key, value) => `${serializePropertyKey(key)}: ${serializeArrayWithFunctions(value, key)}`;
|
|
253
267
|
const mergeSerializedProperties = (jsonObjectLiteral, dynamicProperties) => {
|
|
254
|
-
const
|
|
268
|
+
const joinedDynamicProperties = dynamicProperties.join(', ');
|
|
255
269
|
if (jsonObjectLiteral === '{}') {
|
|
256
|
-
return `{
|
|
270
|
+
return `{ ${joinedDynamicProperties} }`;
|
|
257
271
|
}
|
|
258
|
-
|
|
259
|
-
|
|
272
|
+
/** Drop the trailing `}` of the compact JSON literal so we can append the dynamic properties. */
|
|
273
|
+
const jsonWithoutClosingBrace = jsonObjectLiteral.slice(0, -1);
|
|
274
|
+
return `${jsonWithoutClosingBrace}, ${joinedDynamicProperties} }`;
|
|
260
275
|
};
|
|
261
276
|
/**
|
|
262
277
|
* Serialize a configuration object to a JavaScript object literal for hydration.
|
|
@@ -280,11 +295,10 @@ export function serializeConfigToJs(config) {
|
|
|
280
295
|
assertNoNestedFunctions(value, key);
|
|
281
296
|
});
|
|
282
297
|
const jsonString = serializeJsonObject(restConfig);
|
|
283
|
-
const indentedJsonString = addIndent(jsonString, 6);
|
|
284
298
|
if (dynamicProperties.length === 0) {
|
|
285
|
-
return
|
|
299
|
+
return jsonString;
|
|
286
300
|
}
|
|
287
|
-
return mergeSerializedProperties(
|
|
301
|
+
return mergeSerializedProperties(jsonString, dynamicProperties);
|
|
288
302
|
}
|
|
289
303
|
/**
|
|
290
304
|
* Render the Scalar API Reference as a complete HTML document with client-side
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/server-side-rendering"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [],
|
|
14
|
-
"version": "0.1.
|
|
14
|
+
"version": "0.1.28",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=22"
|
|
17
17
|
},
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@unhead/vue": "^2.1.12",
|
|
32
32
|
"vue": "^3.5.30",
|
|
33
|
-
"@scalar/api-reference": "1.
|
|
34
|
-
"@scalar/types": "0.
|
|
33
|
+
"@scalar/api-reference": "1.62.0",
|
|
34
|
+
"@scalar/types": "0.16.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@hono/node-server": "^1.19.10",
|