Make WordPress Core

Opened 7 years ago

Closed 8 months ago

#36631 closed enhancement (fixed)

wp.template() should throw an error if the template is not found

Reported by: joehoyle's profile joehoyle Owned by: desrosj's profile desrosj
Milestone: 6.1 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch needs-testing
Focuses: javascript Cc:


When calling wp.template() in JS, if the template element does not exist (maybe you forgot to wait for document.ready) a very cryptic error happens ("Uncaught TypeError: Cannot read property 'replace' of undefined"). I'm not totally familiar with how defensive we typically are for things like this - but in this case it would have saved me a good deal of effort if I saw a descriptive error.

Attachments (2)

36631.diff (506 bytes) - added by joehoyle 7 years ago.
36631.2.diff (499 bytes) - added by desrosj 11 months ago.

Download all attachments as: .zip

Change History (11)

7 years ago

This ticket was mentioned in Slack in #core by talldanwp. View the logs.

3 years ago

#2 @noisysocks
3 years ago

  • Keywords needs-refresh added

Good suggestion @joehoyle! The patch doesn't apply cleanly anymore, but if you or someone else is happy to refresh it then I think let's get this in.

#3 @desrosj
11 months ago

  • Keywords 2nd-opinion needs-refresh removed
  • Milestone set to 6.1

Found this one while going through tickets missing a milestone. Adding an updated patch.

@noisysocks Care to give me a sanity check?

11 months ago

This ticket was mentioned in Slack in #core by chaion07. View the logs.

9 months ago

This ticket was mentioned in Slack in #core by hilayt24. View the logs.

9 months ago

#6 @hilayt24
9 months ago

  • Keywords needs-testing added

As per the discussion in the *6.1* Bug-Scrub, the latest patch looks good. I am adding a needs-testing tag to keep things smooth. Thanks, @costdev for the suggestions.

Props: @costdev, @chaion07

Last edited 9 months ago by hilayt24 (previous) (diff)

This ticket was mentioned in Slack in #core by audrasjb. View the logs.

8 months ago

#8 @desrosj
8 months ago

  • Owner set to desrosj
  • Status changed from new to assigned

#9 @desrosj
8 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 54241:

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.

Note: See TracTickets for help on using tickets.