diff --git a/examples/live-reload/src/pages/index.tsx b/examples/live-reload/src/pages/index.tsx index ed57a79..2be481d 100644 --- a/examples/live-reload/src/pages/index.tsx +++ b/examples/live-reload/src/pages/index.tsx @@ -3,6 +3,6 @@ export default () => (

Live Reload Demo

Run this with bun run dev, then edit this file.

The browser will automatically refresh — no manual reload needed.

-

Try changing this text and saving!

+

OMG! Try changing this text and saving!

) diff --git a/examples/live-reload/tsconfig.json b/examples/live-reload/tsconfig.json new file mode 100644 index 0000000..408e62d --- /dev/null +++ b/examples/live-reload/tsconfig.json @@ -0,0 +1,36 @@ +{ + "compilerOptions": { + // Environment setup & latest features + "lib": [ + "ESNext", + "DOM" + ], + "target": "ESNext", + "module": "Preserve", + "moduleDetection": "force", + "jsx": "react-jsx", + "jsxImportSource": "hono/jsx", + "allowJs": true, + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false, + "baseUrl": ".", + "paths": { + "#*": [ + "src/*" + ] + }, + } +} \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index 882a01c..3fb07e7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -146,6 +146,7 @@ export class Hype< // live reload endpoint (dev mode only) if (process.env.NODE_ENV !== 'production') { this.sse('/__hype/reload', () => {}) + this.get('/__hype/ping', c => c.text('ok')) } // healthcheck diff --git a/src/layout.tsx b/src/layout.tsx index 263cb25..b1cd4b7 100644 --- a/src/layout.tsx +++ b/src/layout.tsx @@ -23,7 +23,7 @@ const Layout: FC = ({ children, title, props }) => -const RELOAD_SCRIPT = '{let c=false;const e=new EventSource("/__hype/reload");e.onopen=()=>{if(c)location.reload();c=true};e.onerror=()=>{e.close();let d=50;setTimeout(function r(){fetch("/__hype/reload").then(()=>location.reload()).catch(()=>{d=Math.min(d*1.5,2000);setTimeout(r,d)})},d)}}' +const RELOAD_SCRIPT = '{let c=false;const e=new EventSource("/__hype/reload");e.onopen=()=>{if(c)location.reload();c=true};e.onerror=()=>{e.close();let d=50;setTimeout(function r(){fetch("/__hype/ping").then(()=>location.reload()).catch(()=>{d=Math.min(d*1.5,2000);setTimeout(r,d)})},d)}}' export const ReloadScript: FC = () => isDev ?