vue-snap
vue-snap copied to clipboard
Safari scroll behavior isn't patched on SSR
When using vue-snap
with SSR in a Nuxt app, I noticed that the scroll behavior of Safari isn't smooth when using the arrow buttons. After doing some digging I see where the seamless-scroll-pollyfill
is being included to pollyfill Safari, but it's being excluded from the SSR.
This makes sense as the pollyfill looks for the window
object which won't exist on the server, but it raises the question what is the recommended way of patching Safari if you're using SSR? Would the right approach be to include the polyfill in the mounted()
hook on the client side?
If anybody else encounters this, this is how I resolved it:
<script lang="ts">
import Vue from 'vue'
import { elementScrollToPolyfill } from 'seamless-scroll-polyfill'
export default Vue.extend({
mounted() {
if (!('scrollBehavior' in document.documentElement.style)) {
elementScrollToPolyfill()
}
},
})
</script>
Is this plugin still under active development?