Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Fix SSR #1253

Closed
wants to merge 1 commit into from
Closed

Fix SSR #1253

wants to merge 1 commit into from

Conversation

whyleee
Copy link

@whyleee whyleee commented Dec 1, 2018

Fixes #1223, skips running all code in environments without window object. This is done to avoid ReferenceError: window is not defined error that happens in Node.js when importing iscroll module. Scroller functionality is not required during server-side render, but usually will be triggered on the client-side where window object is available.

Tested on our project with vue-iscroll-view, which is a wrapper Vue component for iscroll. SSR works ignoring scroller functionality and client-side works by applying scroller in mounted hook (only called on client-side), this is done by iscroll-view component.

@whyleee
Copy link
Author

whyleee commented Dec 1, 2018

On second thought I read this w3c/IntersectionObserver#327 and it makes sense 🙂. I'm reverting to conditional module loading and closing the pull request:

import IScrollView from 'vue-iscroll-view'
const IScroll = typeof window != 'undefined' ? require('iscroll') : {}

Vue.use(IScrollView, IScroll)

The problem that I need to mix CommonJS with ES modules for this, but Webpack solves the issue for now and later SSR tools will probably become better 🙂

@whyleee whyleee closed this Dec 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant