Restore missing if statement for scroll preservation