Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88c99d3

Browse files
authored
Merge pull request gridstack#2596 from stephenjason89/fix/ssr
fix(ssr): problem with document not existing on server side
2 parents 5ed9e4e + 3ab632d commit 88c99d3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/gridstack.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export class GridStack {
9494
* let grid = document.querySelector('.grid-stack').gridstack;
9595
*/
9696
public static init(options: GridStackOptions = {}, elOrString: GridStackElement = '.grid-stack'): GridStack {
97+
if(typeof document === 'undefined') {
98+
return null
99+
}
97100
let el = GridStack.getGridElement(elOrString);
98101
if (!el) {
99102
if (typeof elOrString === 'string') {
@@ -121,6 +124,9 @@ export class GridStack {
121124
*/
122125
public static initAll(options: GridStackOptions = {}, selector = '.grid-stack'): GridStack[] {
123126
let grids: GridStack[] = [];
127+
if(typeof document === 'undefined') {
128+
return grids
129+
}
124130
GridStack.getGridElements(selector).forEach(el => {
125131
if (!el.gridstack) {
126132
el.gridstack = new GridStack(el, Utils.cloneDeep(options));

0 commit comments

Comments
 (0)