Skip to content

Commit

Permalink
dynamically import socket.io-client when needed (excalidraw#1631)
Browse files Browse the repository at this point in the history
  • Loading branch information
ad1992 authored May 26, 2020
1 parent 5a64447 commit 5252726
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";

import socketIOClient from "socket.io-client";
import rough from "roughjs/bin/rough";
import { RoughCanvas } from "roughjs/bin/canvas";
import { simplify, Point } from "points-on-curve";
Expand Down Expand Up @@ -804,7 +803,9 @@ class App extends React.Component<any, AppState> {
this.portal.close();
};

private initializeSocketClient = (opts: { showLoadingState: boolean }) => {
private initializeSocketClient = async (opts: {
showLoadingState: boolean;
}) => {
if (this.portal.socket) {
return;
}
Expand Down Expand Up @@ -925,6 +926,10 @@ class App extends React.Component<any, AppState> {
}
};

const { default: socketIOClient }: any = await import(
/* webpackChunkName: "socketIoClient" */ "socket.io-client"
);

this.portal.open(
socketIOClient(SOCKET_SERVER),
roomMatch[1],
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (
/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent) &&
!matchMedia("(display-mode: standalone)").matches
) {
import("pwacompat");
import(/* webpackChunkName: "pwacompat" */ "pwacompat");
}

const SentryEnvHostnameMap: { [key: string]: string } = {
Expand Down

0 comments on commit 5252726

Please sign in to comment.