US citizens overseas are required to declare all income (and capital gains) to the IRS regardless of source. They still have to file returns in the US. Bob will owe tax as a result, but he can probably write off the 4% he payed in PR against his US taxes. He's not a resident of California, so he likely avoids the state tax.
(Note: I don't know specifically about Puerto Rico, but generally the above is the case for US citizens in foreign countries.)
Which seems to support your idea! "Capital gains are sourced to your place of residence."
Any dividend income would be taxable, since you have to file an IRS return for all ex-PR income, but it looks like not the CG.
Quite a loophole - thanks for prompting the research.
EDIT: There are some quite long-term residency requirements to avoid CG on things you owned before moving to PR though. I don't think it'd work in the year timeframe you asked about.
PR is a US Territory. Technically, you never left the country.
"In general, United States citizens and resident aliens who are bona fide residents of Puerto Rico during the entire tax year, which for most individuals is January 1 to December 31, are not required to file a U.S. federal income tax return if they have income only from sources within Puerto Rico." www.irs.gov/taxtopics/tc901.html
There are caveats. One that I know for sure is that if you are self-employed, you still must file & pay FICA taxes to the US federal government.
(Note: I don't know specifically about Puerto Rico, but generally the above is the case for US citizens in foreign countries.)