Record _lastParams for {skip} templates even on initial render (when there are no child elements).
Right now, it doesn't catch parameter changes between the first two renders.
I caught this by running Homeroom's existing test on {skip} instead of hr-idom-skip.
Global []: []
Startblock:
[] is submitted
import 'goog:soy.velog'; // from //javascript/template/soy:soyutils_velog
import * as googSoy from 'goog:goog.soy'; // from //javascript/closure/soy
+import Message from 'goog:jspb.Message'; // from //javascript/apps/jspb:message_lib
import {$$VisualElementData, ElementMetadata, Logger} from 'goog:soy.velog'; // from //javascript/template/soy:soyutils_velog
import * as incrementaldom from 'incrementaldom'; // from //third_party/javascript/incremental_dom:incrementaldom
@@ -110,15 +111,15 @@ export class IncrementalDomRenderer implements IdomRendererApi {
if (goog.DEBUG) {
this.attr('soy-server-key', key);
}
+ // Data is only passed by {skip} elements that are roots of templates.
+ if (goog.DEBUG && el && data) {
+ maybeReportErrors(el, data);
+ }
// Keep going since either elements are being created or continuing will
// be a no-op.
if (!el || !el.hasChildNodes()) {
return true;
}
- // Data is only passed by {skip} elements that are roots of templates.
- if (goog.DEBUG && data) {
- maybeReportErrors(el, data);
- }
// Caveat: if the element has only attributes, we will skip regardless.
this.skip();
this.close();
@@ -380,7 +381,7 @@ export function isMatchingKey(
}
function maybeReportErrors(el: HTMLElement, data: unknown) {
- const stringifiedParams = JSON.stringify(data, null, 2);
+ const stringifiedParams = JSON.stringify(data, jsonProtoReplacer, 2);
if (!el.__lastParams) {
el.__lastParams = stringifiedParams;
return;
@@ -399,6 +400,18 @@ ${el.dataset['debugSoy'] || el.outerHTML}`);
}
}
+/** Serializes JSPB protos using toObject if available. */
+function jsonProtoReplacer(key: string, value: unknown) {
+ if (value instanceof Message && !COMPILED &&
+ // tslint:disable-next-line:no-any Call undeclared function.
+ typeof (value as any)['toObject'] === 'function') {
+ // tslint:disable-next-line:no-any Call undeclared function.
+ JSON.stringify((value as any)['toObject'](), null, 2);
+ }
+ // All other values are serialized as-is, which will recursibly call this.
+ return value;
+}
+
/**
* A Renderer that keeps track of whether it was ever called to render anything,
