File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ let controller : ReadableStreamDefaultController | null = null ;
2+
3+ export async function GET ( ) {
4+ if ( process . env . NODE_ENV !== "development" ) {
5+ return new Response ( "" , { status : 404 } ) ;
6+ }
7+
8+ if ( controller ) {
9+ controller . enqueue ( "data: reload\n\n" ) ;
10+ return Response . json ( { message : "reloaded" } ) ;
11+ }
12+
13+ return new Response (
14+ new ReadableStream ( {
15+ start ( c ) {
16+ controller = c ;
17+ c . enqueue ( "data: connected\n\n" ) ;
18+ } ,
19+ cancel ( ) {
20+ controller = null ;
21+ }
22+ } ) ,
23+ {
24+ headers : {
25+ "Content-Type" : "text/event-stream" ,
26+ "Cache-Control" : "no-cache"
27+ }
28+ }
29+ ) ;
30+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111 url
1212} from "../../config" ;
1313import { HeadMetaComponent } from "../components/components" ;
14+ import DevTools from "../components/dev/DevTools" ;
1415import { fullUrl } from "../utils/url" ;
1516import ClientLayout from "./clientLayout" ;
1617
@@ -62,6 +63,7 @@ export default function RootLayout({
6263 } }
6364 />
6465 < ClientLayout > { children } </ ClientLayout >
66+ < DevTools />
6567 </ body >
6668 </ html >
6769 ) ;
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import dynamic from "next/dynamic" ;
4+
5+ // Dynamic import with NODE_ENV check ensures dev-only components like ReloadBrowser
6+ // are completely excluded from the production bundle via tree-shaking.
7+ // This wrapper exists because layout.tsx is a Server Component, where
8+ // next/dynamic with { ssr: false } is not allowed.
9+ const ReloadBrowser =
10+ process . env . NODE_ENV === "development"
11+ ? dynamic ( ( ) => import ( "./ReloadBrowser" ) , { ssr : false } )
12+ : ( ) => null ;
13+
14+ export default function DevTools ( ) {
15+ return < ReloadBrowser /> ;
16+ }
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { useEffect } from "react" ;
4+
5+ export default function ReloadBrowser ( ) {
6+ useEffect ( ( ) => {
7+ const es = new EventSource ( "/api/dev/reload" ) ;
8+ es . onmessage = ( e ) => {
9+ if ( e . data === "reload" ) window . location . reload ( ) ;
10+ } ;
11+ return ( ) => es . close ( ) ;
12+ } , [ ] ) ;
13+
14+ return null ;
15+ }
You can’t perform that action at this time.
0 commit comments