Q. Must a comma always precede the phrase “such as”? If not, what is the rule for when there should be a comma?

A. You need a comma if what follows is nonrestrictive. Our Q&A has devoted much space to this issue; if you type “restrictive” into the search box, you can access the relevant questions and answers.

Restrictive: I love moments such as those. [I don’t love all moments; this tells which moments I do love.]

Unrestrictive: Don’t you love that lucky, jazzy feeling, such as when you meet someone cute or find money in your pocket? [I love that feeling, unrestricted; here are some examples of it.]

(And thanks to questions such as yours, we now treat this specific question in CMOS; see 6.27 in the sixteenth edition.)