Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d31353

Browse files
authored
enhanced browser logs (#205)
* enhanced browser logs* fix?* fix* version bump
1 parentf63ed09 commit7d31353

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name":"react-router-devtools",
33
"description":"Devtools for React Router - debug, trace, find hydration errors, catch bugs and inspect server/client data with react-router-devtools",
44
"author":"Alem Tuzlak",
5-
"version":"5.0.1",
5+
"version":"5.0.2",
66
"license":"MIT",
77
"keywords": [
88
"react-router",

‎src/client/components/RouteSegmentInfo.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const RouteSegmentInfo = ({ route, i }: { route: UIMatch<unknown, unknown
142142
<button
143143
type="button"
144144
data-testid={`${route.id}-show-route-boundaries`}
145-
className="roundedborder border-green-600 rounded border border-[#1F9CF0] px-2.5 py-0.5 text-sm font-medium text-green-600"
145+
className="border-green-600 rounded border px-2.5 py-0.5 text-sm font-medium text-green-600"
146146
onClick={()=>{
147147
constrouteId=route.id==="root" ?"root" :i.toString()
148148
if(routeId!==settings.hoveredRoute){

‎src/vite/plugin.tsx‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
6262
constincludeClient=args?.includeInProd?.client??false
6363
constincludeServer=args?.includeInProd?.server??false
6464
constincludeDevtools=args?.includeInProd?.devTools??false
65-
65+
letport=5173
6666
letroutes:Route[]=[]
6767
letflatRoutes:Route[]=[]
6868
constappDir=args?.appDir||"./app"
@@ -235,15 +235,30 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
235235
if(server.config.appType!=="custom"){
236236
return
237237
}
238+
if(server.config.server.port){
239+
process.rdt_port=server.config.server.port??5173
240+
port=process.rdt_port
241+
}
242+
238243
server.httpServer?.on("listening",()=>{
239244
process.rdt_port=server.config.server.port??5173
245+
port=process.rdt_port
240246
})
241247
//@ts-ignore - vite 5/6 compat
242248
constchannel=server.hot.channels.find((channel)=>channel.name==="ws")??server.environments?.client.hot
243-
249+
consteditor=args?.editor??DEFAULT_EDITOR_CONFIG
250+
constopenInEditor=async(path:string|undefined,lineNum:string|undefined)=>{
251+
if(!path){
252+
return
253+
}
254+
editor.open(path,lineNum)
255+
}
244256
server.middlewares.use((req,res,next)=>
245257
handleDevToolsViteRequest(req,res,next,(parsedData)=>{
246258
const{ type, data, routine}=parsedData
259+
if(routine==="open-source"){
260+
returnhandleOpenSource({data:{type:data.type, data}, openInEditor, appDir})
261+
}
247262
if(routine==="request-event"){
248263
unusedEvents.set(parsedData.id+parsedData.startTime,parsedData)
249264
for(constclientofserver.hot.channels){
@@ -295,7 +310,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
295310
})
296311

297312
if(!server.config.isProduction){
298-
channel?.on("remove-event",(data,client)=>{
313+
channel?.on("remove-event",(data)=>{
299314
constparsedData=data
300315
const{ id, startTime}=parsedData
301316

@@ -319,13 +334,6 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
319334
})
320335
)
321336
})
322-
consteditor=args?.editor??DEFAULT_EDITOR_CONFIG
323-
constopenInEditor=async(path:string|undefined,lineNum:string|undefined)=>{
324-
if(!path){
325-
return
326-
}
327-
editor.open(path,lineNum)
328-
}
329337

330338
server.hot.on("open-source",(data:OpenSourceData)=>handleOpenSource({ data, openInEditor, appDir}))
331339
server.hot.on("add-route",(data:WriteFileData)=>handleWriteFile({ ...data, openInEditor}))
@@ -362,7 +370,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
362370
}
363371

364372
constcolumn=line.indexOf("console.")
365-
constlogMessage=`"${chalk.magenta("LOG")}${chalk.blueBright(`${id.replace(normalizePath(process.cwd()),"")}:${lineNumber+1}:${column+1}`)}\\n →"`
373+
constlogMessage=`'${chalk.magenta("LOG")}${chalk.blueBright(`http://localhost:${port}/open-source?source=${encodeURIComponent(id.replace(normalizePath(process.cwd()),""))}&line=${lineNumber+1}&column=${column+1}`)}\\n →'`
366374
if(line.includes("console.log(")){
367375
constnewLine=`console.log(${logMessage},`
368376
returnline.replace("console.log(",newLine)

‎src/vite/utils.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
importtype{IncomingMessage,ServerResponse}from"node:http"
2-
importtype{Connect}from"vite"
2+
import{typeConnect,normalizePath}from"vite"
33

44
exportasyncfunctionprocessPlugins(pluginDirectoryPath:string){
55
constfs=awaitimport("node:fs")
@@ -28,6 +28,27 @@ export const handleDevToolsViteRequest = (
2828
next:Connect.NextFunction,
2929
cb:(data:any)=>void
3030
)=>{
31+
if(req.url?.includes("open-source")){
32+
constsearchParams=newURLSearchParams(req.url.split("?")[1])
33+
constsource=searchParams.get("source")
34+
constline=searchParams.get("line")
35+
constcolumn=searchParams.get("column")
36+
cb({
37+
type:"open-source",
38+
routine:"open-source",
39+
data:{
40+
source:source ?normalizePath(`${process.cwd()}/${source}`) :undefined,
41+
line,
42+
column,
43+
},
44+
})
45+
res.setHeader("Content-Type","text/html")
46+
res.write(`<script>
47+
window.close();
48+
</script>`)
49+
res.end()
50+
return
51+
}
3152
if(!req.url?.includes("react-router-devtools-request")){
3253
returnnext()
3354
}

‎test-apps/react-router-vite/app/routes/_index.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default function Index() {
7777
data.append("person.name","test1");
7878
data.append("person.surname","test1");
7979
data.append("obj",JSON.stringify({test:"test"}));
80+
console.log(data);
8081
return(
8182
<divstyle={{fontFamily:"system-ui, sans-serif",lineHeight:"1.8"}}>
8283
<h1>Welcome to Remix</h1>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exportdefaultfunctionIndex(){
2+
console.log("Epic test")
3+
return<div>
4+
Epic test
5+
</div>
6+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp