Is it a problem to have gaps and holes in the subfloor of a hardwood floor?
Vermin would be my only concern. Spray foam is not the best sealer for the critters but staple some steel wool over the opening and put the spray foam on that.
The foam encapsulates the steel wool using less foam and critters don’t like chewing on the steel wool (they will tunnel through spray foam very quickly).
Those gaps look larger than I like but as long as your trim covers the edges there is nothing to worry about, possibly a rodent highway under the trim if not filled but no structural issues.