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

feat: Limit route info events to 3 recent entries #164

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions src/client/context/rdtReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export type RemixDevToolsState = {
timeline: TimelineEvent[]
terminals: Terminal[]
settings: {
/**
* The number of events to keep in history per route
* @default 30
*/
eventsToKeep: number
/**
* The breakpoints to show in the corner so you can see the current breakpoint that you defined
*/
Expand Down Expand Up @@ -167,6 +172,7 @@ export const initialState: RemixDevToolsState = {
terminals: [{ id: 0, locked: false, output: [], history: [] }],
server: undefined,
settings: {
eventsToKeep: 30,
showRouteBoundariesOn: "click",
breakpoints: [
{ name: "", min: 0, max: 639 },
Expand Down
9 changes: 5 additions & 4 deletions src/client/hooks/useDevServerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useNavigation } from "@remix-run/react"
import { useEffect } from "react"
import type { ActionEvent, LoaderEvent } from "../../server/event-queue.js"
import type { ServerInfo } from "../context/rdtReducer.js"
import { useServerInfo } from "../context/useRDTContext.js"
import { useServerInfo, useSettingsContext } from "../context/useRDTContext.js"
import { cutArrayToLastN } from "../utils/common.js"

const updateRouteInfo = (
Expand Down Expand Up @@ -51,6 +51,7 @@ const updateRouteInfo = (
const useDevServerConnection = () => {
const navigation = useNavigation()
const { server, setServerInfo } = useServerInfo()
const { settings } = useSettingsContext()

// Pull the event queue from the server when the page is idle
useEffect(() => {
Expand All @@ -67,8 +68,8 @@ const useDevServerConnection = () => {
for (const routeInfo of Object.values(events)) {
const { loader, action } = routeInfo as any
const events = [
loader.map((e: any) => ({ type: "loader", data: e })),
action.map((e: any) => ({ type: "action", data: e })),
loader.slice(-settings.eventsToKeep).map((e: any) => ({ type: "loader", data: e })),
action.slice(-settings.eventsToKeep).map((e: any) => ({ type: "action", data: e })),
].flat()
for (const event of events) {
updateRouteInfo(server, routes, event, false)
Expand All @@ -86,7 +87,7 @@ const useDevServerConnection = () => {
import.meta.hot.dispose(cb2)
}
}
}, [server, setServerInfo])
}, [server, setServerInfo, settings.eventsToKeep])

const isConnected = typeof import.meta.hot !== "undefined"

Expand Down
15 changes: 15 additions & 0 deletions src/client/tabs/SettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const SettingsTab = () => {
const [maxHeight, setMaxHeight] = useState(settings.maxHeight.toString())
const [expansionLevel, setExpansionLevel] = useState(settings.expansionLevel.toString())
const [openHotkey, setOpenHotkey] = useState(settings.openHotkey.toString())
const [eventsToKeep, setEventsToKeep] = useState(settings.eventsToKeep.toString())

return (
<Stack className="mb-4">
Expand Down Expand Up @@ -206,6 +207,20 @@ export const SettingsTab = () => {
}
}}
/>
<Input
name="eventsToKeep"
id="eventsToKeep"
label="Number of events to keep in history"
hint="The number of loader/action events to keep in history per route. Minimum: 1, Maximum: 100"
value={eventsToKeep}
onChange={(e) => setEventsToKeep(e.target.value ?? "")}
onBlur={(e) => {
const value = Number.parseInt(e.target.value)
if (value && !Number.isNaN(value) && value >= 1 && value <= 100) {
setSettings({ eventsToKeep: value })
}
}}
/>
</Stack>
</Stack>
)
Expand Down