Skip to content
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

Load isomorphic-ws via import rather than async import #1048

Merged
merged 7 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twenty-emus-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Converted `isomorphic-ws` to a synchronous import.
15 changes: 2 additions & 13 deletions src/utils/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MessageEvent, WebSocket } from 'isomorphic-ws'
import WebSocket from 'isomorphic-ws'
import type { MessageEvent } from 'isomorphic-ws'

import {
HttpRequestError,
Expand Down Expand Up @@ -155,18 +156,6 @@ export async function getSocket(url: string) {
const { schedule } = createBatchScheduler<undefined, [Socket]>({
id: url,
fn: async () => {
let WebSocket = await import('isomorphic-ws')
// Workaround for Vite.
// https://github.com/vitejs/vite/issues/9703
// TODO: Remove when issue is resolved.
if (
(WebSocket as unknown as { default?: typeof WebSocket }).default
?.constructor
)
WebSocket = (WebSocket as unknown as { default: typeof WebSocket })
.default
else WebSocket = WebSocket.WebSocket

const webSocket = new WebSocket(url)

// Set up a cache for incoming "synchronous" requests.
Expand Down