Trying to visit a page of a single entry that is disabled should return a 404, but instead, it renders the page with the error Variable "entry" does not exist..
Most likely this is happening because your single section is set to a public template path (where none of the template segments begin with _), and where the template path matches the single’s URI.
For example, if your single’s URI is about, and the template path is about or about.twig.
In that case, if the entry is disabled, Craft will route to the template directly.
But the template is assuming that an entry variable was passed to it, which will only actually happen if the request had been routed to the (enabled) single entry first.
The way to fix this would be to make it a private template path (about.twig → _about.twig) and update the section settings accordingly.
@brandonkelly Oh, interesting.
This must be due to a recent change, because this project that it occurred on is duplicated from a project that is running on Craft 3.5.9 and works as expected.
Is my theory correct? If so it’s worked that way since the beginning.
Yes, but I don't believe that this behavior is the same as before.
I’m 100% certain this is the way it’s always worked.
Maybe I haven't had enough use cases for singles to be disabled, but you seem to be right.
I must have tested something wrong, because going back and testing gives me the expected result (as you outlined). Sorry for the false alarm.
I did move to using prefixing templates with underscores a while back, so I probably just never realized this interaction. Going to have to check in on some older projects.