Transit isn't allowed in TPE; transit to enter China in general is only allowed if there are no direct flights, which is not the case if you're starting in SF. Also, if you're only planning on spending 4 weeks in China, most of that will be eaten up by quarantine.