I experienced a few instances of the issue like this. I developed an image slider component in AEM. As you click on the pre and next button, the images are supposed to scroll to the left or the right. However the functionality doesn't work in the Preview mode. When I publish the page, the component works fine. Another problem is with the sticky menu effect on the client side. I put the code in the client lib. It doesn't work in Preview mode but it works fine when I publish the page. I was wondering if anyone knows this issue or knows if it is possible to fix it.
Do your Author and Publisher instances implement the same code minification policies? You can check this by finding and comparing the com.adobe.granite.ui.clientlibs.impl.HtmlLibraryManagerImpl config on each instance. I've had the issue before where my code was being minified on one instance and not the other and it was causing issues (due to conflict between Webpack minification and GCC minification).
Thank you everyone for the replies. After digging the code thoroughly. I eventually found out it was due to CSS. Our internal developer wrote two sets of css for both author and publish so the component looks ok in both views. However, he didn't account for preview mode which has caused a rendering issue.