Skip to content

Commit 826e1a3

Browse files
committed
General: Throw a more descriptive error when templates are not found.
When `wp.template()` is called in JavaScript for a template element that does not exist, a very nondescript error message is currently returned (“Uncaught TypeError: Cannot read property `replace` of `undefined`”). This updates adds a check for this scenario and a new “Template not found” error is now thrown instead. Props joehoyle, noisysocks, hilayt24. Fixes #36631. git-svn-id: https://develop.svn.wordpress.org/trunk@54241 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7a6ba32 commit 826e1a3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/js/_enqueues/wp/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ window.wp = window.wp || {};
3636
};
3737

3838
return function ( data ) {
39+
if ( ! document.getElementById( 'tmpl-' + id ) ) {
40+
throw new Error( 'Template not found: ' + '#tmpl-' + id );
41+
}
3942
compiled = compiled || _.template( $( '#tmpl-' + id ).html(), options );
4043
return compiled( data );
4144
};

0 commit comments

Comments
 (0)