Make WordPress Core

Opened 8 years ago

Closed 22 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:

Description

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 8 years ago.
36631.2.diff (499 bytes) - added by desrosj 2 years ago.

Download all attachments as: .zip

Change History (11)

@joehoyle
8 years ago

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


4 years ago

#2 @noisysocks
4 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
2 years 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?

@desrosj
2 years ago

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


2 years ago

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


2 years ago

#6 @hilayt24
2 years 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

Version 0, edited 2 years ago by hilayt24 (next)

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


22 months ago

#8 @desrosj
22 months ago

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

#9 @desrosj
22 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.