dynamically import socket.io-client when needed (#1631)

This commit is contained in:
Aakansha Doshi 2020-05-27 00:21:03 +05:30 committed by GitHub
parent 5a64447adc
commit 5252726307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,5 @@
import React from "react"; import React from "react";
import socketIOClient from "socket.io-client";
import rough from "roughjs/bin/rough"; import rough from "roughjs/bin/rough";
import { RoughCanvas } from "roughjs/bin/canvas"; import { RoughCanvas } from "roughjs/bin/canvas";
import { simplify, Point } from "points-on-curve"; import { simplify, Point } from "points-on-curve";
@ -804,7 +803,9 @@ class App extends React.Component<any, AppState> {
this.portal.close(); this.portal.close();
}; };
private initializeSocketClient = (opts: { showLoadingState: boolean }) => { private initializeSocketClient = async (opts: {
showLoadingState: boolean;
}) => {
if (this.portal.socket) { if (this.portal.socket) {
return; return;
} }
@ -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( this.portal.open(
socketIOClient(SOCKET_SERVER), socketIOClient(SOCKET_SERVER),
roomMatch[1], roomMatch[1],

View File

@ -18,7 +18,7 @@ if (
/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent) && /\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent) &&
!matchMedia("(display-mode: standalone)").matches !matchMedia("(display-mode: standalone)").matches
) { ) {
import("pwacompat"); import(/* webpackChunkName: "pwacompat" */ "pwacompat");
} }
const SentryEnvHostnameMap: { [key: string]: string } = { const SentryEnvHostnameMap: { [key: string]: string } = {