New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSR problem in vue.draggable context #1646
Comments
I am trying to figure out a solution but it does not make sense to me since the older versions of sortable had the exact same reference to the navigator. The only difference is that in the older versions, Sortable threw an error if the window was not defined, but that is still an error so I don't understand how SSR ever worked with Sortable. |
The difference should be the code executed just by calling import vs the code executed by the new Sortable. |
In the previous versions (such as 1.9.0), the navigator code was executed when Sortable was imported. You can see the code here. It is not within the Sortable function but within the UMD function that is called when the script is loaded. |
That's weird |
In version 1.9.0, you had this early return:
Could you re-introduce it in version 1.10? |
@David-Desmaisons I have done this in commit 5fccf71. |
"TypeError: u is not a constructor" |
@David-Desmaisons Could it be possible to release a new version with these changes? |
I am using it in vue-electron it not coming up |
it seems it can only work on browser environment |
Error in mounted hook: "TypeError: Sortable is not a constructor" |
@David-Desmaisons Is it confirmed that it fixes the SSR issue? |
@owen-m1 I will perform some manual test with the fixed version locally. If everything runs OK, I will let you know. |
Hi Owen, I've tested the fix, and it doesn't work for me. The problem is that there is quite a few browser specific code executed as soon as someone import/require this library. I'm using Vue.Draggable that require Sortable. The import is made on serverside and on clientside. But the Sortable constructor is only called in I've a commit with the changes Tarrask@8ff64de that works in my case. It's a bit to early to submit a merge request as I don't know yet if it break anything else. For exemple, if you call the constructor more than one time, it will register some listeners twice. |
@Tarrask Ok, so Sortable never worked for SSR, even before version 1.10.0. That makes more sense. |
@owen-m1 Exactly, that what I found. But importing it should be harmless. Actually, a very simple test is with a small js script that just require the library, eg: |
@Tarrask Thank you, I see the issue now. Sortable never supported SSR, but if you imported Sortable without a window object, it would only throw an error when you called the Sortable constructor. |
@owen-m1 to clarify: sortable by itself did not support SSR but vue.draggable do. Mainly vue.draggable is avoiding to run any sortable code in a node context. |
Create file test.js containing: Run in command line |
I have traced some refresh issues back to this, what's the ETA of the fix? Thanks! |
@UnaiRa @stuta Please try building commit 576e335 and tell me if it fixes the problem. I just made it so that Sortable will not throw any errors on import if the window or document is not defined. Obviously it won't work properly unless it is imported in a browser context, but this has always been the behaviour of Sortable. |
@owen-m1 for me, it works |
@owen-m1 Great, is this making it to a RC anytime soon? |
@UnaiRa I will release 1.10.1 tonight. |
Thanks @owen-m1 , look forward to new release. |
@David-Desmaisons @serdarkok @UnaiRa @Tarrask 1.10.1 is released |
Thanks!!! I will release a new version of Vue.draggable by Today |
Problem:
Hello @owen-m1 , version 1.1.0.0 of sortable.js introduced a call to
navigator
global property.This is breaking SSR usage of vue.draggable: building the template on the server-side using node (none browser context).
I tried a fix to require sortable.js only in browser context (SortableJS/Vue.Draggable#724), but it seems
I can not think of another fix on vue.draggable side thougth.
Could it be possible to check for navigator early in sortable.js to avoid to raise exception when navigator is not defined?
The text was updated successfully, but these errors were encountered: