@@ -62,7 +62,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
6262const includeClient = args ?. includeInProd ?. client ?? false
6363const includeServer = args ?. includeInProd ?. server ?? false
6464const includeDevtools = args ?. includeInProd ?. devTools ?? false
65-
65+ let port = 5173
6666let routes :Route [ ] = [ ]
6767let flatRoutes :Route [ ] = [ ]
6868const appDir = args ?. appDir || "./app"
@@ -235,15 +235,30 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
235235if ( server . config . appType !== "custom" ) {
236236return
237237}
238+ if ( server . config . server . port ) {
239+ process . rdt_port = server . config . server . port ?? 5173
240+ port = process . rdt_port
241+ }
242+
238243server . httpServer ?. on ( "listening" , ( ) => {
239244process . rdt_port = server . config . server . port ?? 5173
245+ port = process . rdt_port
240246} )
241247//@ts -ignore - vite 5/6 compat
242248const channel = server . hot . channels . find ( ( channel ) => channel . name === "ws" ) ?? server . environments ?. client . hot
243-
249+ const editor = args ?. editor ?? DEFAULT_EDITOR_CONFIG
250+ const openInEditor = async ( path :string | undefined , lineNum :string | undefined ) => {
251+ if ( ! path ) {
252+ return
253+ }
254+ editor . open ( path , lineNum )
255+ }
244256server . middlewares . use ( ( req , res , next ) =>
245257handleDevToolsViteRequest ( req , res , next , ( parsedData ) => {
246258const { type, data, routine} = parsedData
259+ if ( routine === "open-source" ) {
260+ return handleOpenSource ( { data :{ type :data . type , data} , openInEditor, appDir} )
261+ }
247262if ( routine === "request-event" ) {
248263unusedEvents . set ( parsedData . id + parsedData . startTime , parsedData )
249264for ( const client of server . hot . channels ) {
@@ -295,7 +310,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
295310} )
296311
297312if ( ! server . config . isProduction ) {
298- channel ?. on ( "remove-event" , ( data , client ) => {
313+ channel ?. on ( "remove-event" , ( data ) => {
299314const parsedData = data
300315const { id, startTime} = parsedData
301316
@@ -319,13 +334,6 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
319334} )
320335)
321336} )
322- const editor = args ?. editor ?? DEFAULT_EDITOR_CONFIG
323- const openInEditor = async ( path :string | undefined , lineNum :string | undefined ) => {
324- if ( ! path ) {
325- return
326- }
327- editor . open ( path , lineNum )
328- }
329337
330338server . hot . on ( "open-source" , ( data :OpenSourceData ) => handleOpenSource ( { data, openInEditor, appDir} ) )
331339server . hot . on ( "add-route" , ( data :WriteFileData ) => handleWriteFile ( { ...data , openInEditor} ) )
@@ -362,7 +370,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
362370}
363371
364372const column = line . indexOf ( "console." )
365- const logMessage = `" ${ chalk . magenta ( "LOG" ) } ${ chalk . blueBright ( `${ id . replace ( normalizePath ( process . cwd ( ) ) , "" ) } : ${ lineNumber + 1 } : ${ column + 1 } ` ) } \\n →" `
373+ const logMessage = `' ${ chalk . magenta ( "LOG" ) } ${ chalk . blueBright ( `http://localhost: ${ port } /open-source?source= ${ encodeURIComponent ( id . replace ( normalizePath ( process . cwd ( ) ) , "" ) ) } &line= ${ lineNumber + 1 } &column= ${ column + 1 } ` ) } \\n →' `
366374if ( line . includes ( "console.log(" ) ) {
367375const newLine = `console.log(${ logMessage } ,`
368376return line . replace ( "console.log(" , newLine )