elliott/hydratable
Rich Harris 1 day ago
parent 9343114bae
commit ce926c37f9

@ -59,7 +59,12 @@ function encode(key, value, values, unresolved) {
serialize_promise.finally(() => unresolved?.delete(serialize_promise)); serialize_promise.finally(() => unresolved?.delete(serialize_promise));
const index = values.push(serialize_promise) - 1; const index = values.push(serialize_promise) - 1;
const result = `d(${index})`;
// in dev, we serialize promises as `d("1")` instead of `d(1)`, because it's
// impossible for that string to occur 'naturally' (since the quote marks
// would have to be escaped). this allows us to check that repeat occurrences
// of a given hydratable are identical with a simple string comparison
const result = DEV ? `d("${index}")` : `d(${index})`;
if (DEV) { if (DEV) {
(entry.promises ??= []).push( (entry.promises ??= []).push(

@ -654,7 +654,12 @@ export class Renderer {
return null; return null;
} }
const values = await Promise.all(ctx.values); let values = await Promise.all(ctx.values);
if (DEV) {
// turn `d("1")` into `d(1)` — see `hydratable.js` for an explanation
values = values.map((v) => v.replace(/d\("(\d+)"\)/g, (_, i) => `d(${i})`));
}
// TODO csp -- have discussed but not implemented // TODO csp -- have discussed but not implemented
return ` return `

Loading…
Cancel
Save