> the demand and supply must always match
Correct. Overproduction results in increase in grid frequency which can cause a lot of damage.
> this means that that you produce more than you need and have to either sell outside ... or switch off the source
Or import less (Cali imports up to ~30% of its power from Arizona and Utah). In this case, the a good chunk of that excess power seems to have been absorbed by temporarily increasing demand through charging grid scale batteries. That energy can be (and has been) released later in the day to help offset peak loads, allowing utilities to avoid spinning up expensive gas turbines.
> If on the other hand they invested in say nuclear this would not be necessary
Nuclear is far and away the most expensive and has the longest lead time. It also has a problem of needing large supplies of water, and that water needs to be not too warm or else they need to throttle or shut down the plant. Drought and heat waves are both issues in California so expanding nuclear power is difficult even if the local population was accepting of their presence.
=Smidge=