Skip to content

Commit

Permalink
Completely removed remix forge integration (#165)
Browse files Browse the repository at this point in the history
* Potential fix for ws issue

* Potential fix for ws issue
  • Loading branch information
AlemTuzlak authored Nov 18, 2024
1 parent 4a177ed commit 28711a9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 80 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.

3 changes: 1 addition & 2 deletions 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 Expand Up @@ -139,7 +139,6 @@
"react-d3-tree": "^3.6.2",
"react-diff-viewer-continued": "^3.3.1",
"react-hotkeys-hook": "^4.5.0",
"react-use-websocket": "^4.8.1",
"tailwind-merge": "^1.14.0"
}
}
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
54 changes: 3 additions & 51 deletions src/client/hooks/useRemixForgeSocket.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
import { useState } from "react"
import { type Options, ReadyState } from "react-use-websocket"
import useWebSocket from "react-use-websocket"
import { useSettingsContext, useTerminalContext } from "../context/useRDTContext.js"

const RETRY_COUNT = 2

export const useRemixForgeSocket = (options?: Options) => {
const { settings, setSettings } = useSettingsContext()
const { terminals, toggleTerminalLock, setProcessId } = useTerminalContext()
const { shouldConnectWithForge, port } = settings
const [retryCount, setRetryCount] = useState(0)
const opts: Options = {
...options,
share: true,
shouldReconnect: () => true,
reconnectAttempts: RETRY_COUNT,
reconnectInterval: 0,
onClose: (e) => {
// connection closed by remix forge
if (e.code === 1005) {
setSettings({ shouldConnectWithForge: false })
setRetryCount(0)
for (const terminal of terminals) {
toggleTerminalLock(terminal.id, false)
setProcessId(terminal.id, undefined)
}

return
}
if (retryCount < RETRY_COUNT) {
return setRetryCount(retryCount + 1)
}
setSettings({ shouldConnectWithForge: false })
},
}

const properties = useWebSocket(`ws://localhost:${port}`, opts, shouldConnectWithForge)

const connectionStatus = {
[ReadyState.CONNECTING]: "Connecting",
[ReadyState.OPEN]: "Open",
[ReadyState.CLOSING]: "Closing",
[ReadyState.CLOSED]: "Closed",
[ReadyState.UNINSTANTIATED]: "Uninstantiated",
}[properties.readyState]
const isConnected = properties.readyState === ReadyState.OPEN
const isConnecting = properties.readyState === ReadyState.CONNECTING

return { ...properties, connectionStatus, isConnected, isConnecting }
export const useRemixForgeSocket = (options?: any) => {
return { sendJsonMessage: (obj: any) => {}, isConnected: false, isConnecting: false }
}

interface RemixForgeMessage extends Record<string, unknown> {
Expand All @@ -56,7 +8,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
23 changes: 1 addition & 22 deletions src/client/layout/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ const Tab = ({
}

const Tabs = ({ plugins, setIsOpen }: TabsProps) => {
const { settings, setSettings } = useSettingsContext()
const { settings } = useSettingsContext()
const { htmlErrors } = useHtmlErrors()
const { setPersistOpen } = usePersistOpen()
const { activeTab } = settings
const { isConnected, isConnecting } = useRemixForgeSocket()
const { visibleTabs } = useTabs(isConnected, isConnecting, plugins)
const shouldShowConnectToForge = !isConnected || isConnecting
const scrollRef = useHorizontalScroll()
const { setDetachedWindowOwner, detachedWindowOwner, detachedWindow } = useDetachedWindowControls()
const handleDetachment = () => {
Expand Down Expand Up @@ -117,26 +116,6 @@ const Tabs = ({ plugins, setIsOpen }: TabsProps) => {
/>
))}
<div className={clsx("mt-auto flex w-full flex-col items-center")}>
{shouldShowConnectToForge && (
<Tab
tab={{
id: "connect",
name: isConnecting ? "Connecting to Forge..." : "Connect to Remix Forge",
requiresForge: false,
hideTimeline: false,
component: <></>,
icon: <Icon name="Radio" size="md" />,
}}
className={twMerge(
clsx(
isConnecting && "pointer-events-none animate-pulse cursor-default",
"mt-auto w-full ",
detachedWindow ? "mr-0" : ""
)
)}
onClick={() => setSettings({ shouldConnectWithForge: true })}
/>
)}
{!detachedWindow && setIsOpen && (
<>
{!detachedWindowOwner && (
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 28711a9

Please sign in to comment.