Skip to content

Commit

Permalink
Potential fix for ws issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AlemTuzlak committed Nov 18, 2024
1 parent 4a177ed commit a095126
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "remix-development-tools",
"description": "Remix development tools - a set of tools for developing/debugging Remix.run apps",
"author": "Alem Tuzlak",
"version": "4.7.6",
"version": "4.7.7",
"license": "MIT",
"keywords": [
"remix",
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/NewRouteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DEFAULT_VALUES = {

const NewRouteForm = () => {
const { sendJsonMessage } = useRemixForgeSocket({
onMessage: (e) => {
onMessage: (e: { data: any }) => {
const messageData = e.data
if (messageData.type === "route_added") {
setNewRouteInfo(DEFAULT_VALUES)
Expand Down
17 changes: 12 additions & 5 deletions src/client/hooks/useRemixForgeSocket.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { useState } from "react"
import { type Options, ReadyState } from "react-use-websocket"
import useWebSocket from "react-use-websocket"

enum ReadyState {
UNINSTANTIATED = -1,
CONNECTING = 0,
OPEN = 1,
CLOSING = 2,
CLOSED = 3,
}
import { useSettingsContext, useTerminalContext } from "../context/useRDTContext.js"

const RETRY_COUNT = 2

export const useRemixForgeSocket = (options?: Options) => {
export const useRemixForgeSocket = (options?: any) => {
const { settings, setSettings } = useSettingsContext()
const { terminals, toggleTerminalLock, setProcessId } = useTerminalContext()
const { shouldConnectWithForge, port } = settings
const [retryCount, setRetryCount] = useState(0)
const opts: Options = {
const opts: any = {
...options,
share: true,
shouldReconnect: () => true,
reconnectAttempts: RETRY_COUNT,
reconnectInterval: 0,
onClose: (e) => {
onClose: (e: any) => {
// connection closed by remix forge
if (e.code === 1005) {
setSettings({ shouldConnectWithForge: false })
Expand Down Expand Up @@ -56,7 +63,7 @@ interface RemixForgeMessage extends Record<string, unknown> {
data?: string
}

export const useRemixForgeSocketExternal = (options?: Options) => {
export const useRemixForgeSocketExternal = (options?: any) => {
const { sendJsonMessage, ...rest } = useRemixForgeSocket(options)
const sendJsonMessageExternal = (message: RemixForgeMessage) => {
sendJsonMessage({ ...message, type: "plugin" })
Expand Down
4 changes: 2 additions & 2 deletions src/client/tabs/TerminalTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Terminal = ({ onClose, terminal, projectCommands }: TerminalProps) => {
}, [terminal.output])

const { sendJsonMessage } = useRemixForgeSocket({
onMessage: (message) => {
onMessage: (message: any) => {
try {
const data = JSON.parse(message.data)
// Check if command was sent from this terminal
Expand Down Expand Up @@ -149,7 +149,7 @@ const TerminalTab = () => {
const { terminals, addOrRemoveTerminal } = useTerminalContext()
const [projectCommands, setProjectCommands] = useState<Record<string, string>>()
const { sendJsonMessage } = useRemixForgeSocket({
onMessage: (message) => {
onMessage: (message: any) => {
try {
const data = JSON.parse(message.data)
if (data.type === "commands") {
Expand Down

0 comments on commit a095126

Please sign in to comment.