Such as is a phrase with more than one meaning, and this can cause complications.
From English Grammar Today:
We can use such as to introduce an example or examples of something
we mention. We normally use a comma before such as when we present a
list of examples. Where there is just one example, we don’t need a
comma:
(1) The shop specialises in tropical fruits, such as pineapples, mangoes
and papayas. (… for example, pineapples, mangoes and papayas.)
(2) Countries such as Sweden have a long record of welcoming refugees from all over the world.
Such as is similar to like for introducing examples, but it is more formal, and is used more in writing than like.
But this does not distinguish the different senses; in (1) such as means eg / for instance, whereas in (2) it means which are similar in nature to.
ODO brings out this distinction:
such as PHRASE
1: For example.
‘wild flowers such as mountain pansy and wild thyme’
2: Of a kind that; like.
‘an event such as we've shared’
Sometimes either reading is available, and then the comma is used to disambiguate:
"The diagram illustrates the process used to produce electricity using fossil fuels, such as coal." = "The diagram illustrates the process used to produce electricity using fossil fuels – for instance, coal." (non-restrictive)
whereas
"The diagram illustrates the process used to produce electricity using fossil fuels such as coal." = "The diagram illustrates the process used to produce electricity using coal and those fossil fuels which are similar." (restrictive / defining: only the fossil fuels which are (for the purposes of this presentation) similar to coal)
And in fact, the 'for instance' sense always takes the comma whereas the 'which may be classed together with' //'of a/the kind that' sense never does.