Skip to content

Commit c17d55b

Browse files
committed
replace next-watch-remote with custom setup
1 parent abd3e7a commit c17d55b

File tree

7 files changed

+138
-61
lines changed

7 files changed

+138
-61
lines changed

next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const nextConfig = {
1212
scrollRestoration: true,
1313
reactCompiler: true,
1414
},
15+
1516
env: {},
1617
serverExternalPackages: [],
1718
webpack: (config, {dev, isServer, ...options}) => {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "CC",
66
"scripts": {
77
"analyze": "ANALYZE=true next build",
8-
"dev": "next-remote-watch ./src/content",
8+
"dev": "next dev",
99
"build": "next build && node --experimental-modules ./scripts/downloadFonts.mjs",
1010
"lint": "next lint",
1111
"lint:fix": "next lint --fix",
@@ -34,7 +34,7 @@
3434
"date-fns": "^2.16.1",
3535
"debounce": "^1.2.1",
3636
"github-slugger": "^1.3.0",
37-
"next": "^15.1.5",
37+
"next": "^15.2.0-canary.33",
3838
"next-remote-watch": "^1.0.0",
3939
"parse-numeric-range": "^1.2.0",
4040
"react": "^19.0.0",
@@ -64,6 +64,7 @@
6464
"autoprefixer": "^10.4.2",
6565
"babel-eslint": "10.x",
6666
"babel-plugin-react-compiler": "19.0.0-beta-e552027-20250112",
67+
"chokidar": "^4.0.3",
6768
"eslint": "7.x",
6869
"eslint-config-next": "12.0.3",
6970
"eslint-config-react-app": "^5.2.1",

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {siteConfig} from '../siteConfig';
2-
32
import {Analytics} from 'components/Analytics';
43
import {ScrollHandler} from 'components/SafariScrollHandler';
54

@@ -10,6 +9,7 @@ import '../styles/sandpack.css';
109

1110
import {generateMetadata as generateSeoMetadata} from '../utils/generateMetadata';
1211
import {Suspense} from 'react';
12+
import {DevContentRefresher} from 'components/DevContentRefresher';
1313

1414
export async function generateMetadata() {
1515
const metadata = generateSeoMetadata({
@@ -224,7 +224,7 @@ export default function RootLayout({children}: {children: React.ReactNode}) {
224224
<ScrollHandler />
225225
<ThemeScript />
226226
<UwuScript />
227-
227+
{process.env.NODE_ENV !== 'production' && <DevContentRefresher />}
228228
{children}
229229
<Suspense fallback={null}>
230230
<Analytics />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use client';
2+
3+
import {useRouter} from 'next/navigation';
4+
import {useRef, useEffect} from 'react';
5+
6+
export function DevContentRefresher() {
7+
const router = useRouter();
8+
const wsRef = useRef<WebSocket | null>(null);
9+
10+
useEffect(() => {
11+
wsRef.current = new WebSocket('ws://localhost:3001');
12+
13+
wsRef.current.onmessage = (event) => {
14+
const message = JSON.parse(event.data);
15+
16+
if (message.event === 'refresh') {
17+
console.log('Refreshing content...');
18+
// @ts-ignore
19+
router.hmrRefresh(); // Triggers client-side refresh
20+
}
21+
};
22+
23+
return () => {
24+
wsRef.current?.close();
25+
};
26+
}, [router]);
27+
28+
return null;
29+
}

src/content/learn/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Quick Start
44

55
<Intro>
66

7-
Welcome to the React documentation! This page will give you an introduction to 80% of the React concepts that you will use on a daily basis.
7+
Welcome to the React! This page will give you an introduction to 80% of the React concepts that you will use on a daily basis.
88

99
</Intro>
1010

src/instrumentation.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export function register() {
2+
if (
3+
process.env.NODE_ENV === 'development' &&
4+
process.env.NEXT_RUNTIME === 'nodejs'
5+
) {
6+
// watch for changes in the ./src/content directory
7+
// and trigger an HMR update when a change is detected via a custom WebSocket setup
8+
const chokidar = require('chokidar');
9+
const path = require('path');
10+
const ws = require('ws');
11+
12+
const wsServer = new ws.Server({
13+
port: 3001,
14+
});
15+
16+
function triggerRefresh() {
17+
wsServer.clients.forEach((client) => {
18+
if (client.readyState === WebSocket.OPEN) {
19+
client.send(JSON.stringify({event: 'refresh'}));
20+
}
21+
});
22+
}
23+
24+
// the process is in .next so we need to go up two level
25+
const contentDir = path.resolve(__dirname, '../../src/content');
26+
const watcher = chokidar.watch(contentDir, {
27+
ignoreInitial: true,
28+
});
29+
30+
watcher.on('all', () => {
31+
triggerRefresh();
32+
});
33+
}
34+
}

yarn.lock

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,10 +1225,10 @@
12251225
unist-util-visit "^4.0.0"
12261226
vfile "^5.0.0"
12271227

1228-
"@next/env@15.1.5":
1229-
version "15.1.5"
1230-
resolved "https://registry.yarnpkg.com/@next/env/-/env-15.1.5.tgz#2a87f0be705d40b7bd1bf8c66581edc32dcd2b1f"
1231-
integrity sha512-jg8ygVq99W3/XXb9Y6UQsritwhjc+qeiO7QrGZRYOfviyr/HcdnhdBQu4gbp2rBIh2ZyBYTBMWbPw3JSCb0GHw==
1228+
"@next/env@15.2.0-canary.33":
1229+
version "15.2.0-canary.33"
1230+
resolved "https://registry.yarnpkg.com/@next/env/-/env-15.2.0-canary.33.tgz#5cd769cca64e09564e80817b6b6aeaba472ea9e9"
1231+
integrity sha512-y3EPM+JYKU8t2K+i6bc0QrotEZVGpqu9eVjprj4cfS8QZyZcL54s+W9aGB0TBuGavU9tQdZ50W186+toeMV+hw==
12321232

12331233
12341234
version "12.0.3"
@@ -1237,45 +1237,45 @@
12371237
dependencies:
12381238
glob "7.1.7"
12391239

1240-
"@next/swc-darwin-arm64@15.1.5":
1241-
version "15.1.5"
1242-
resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.1.5.tgz#2b59120c1576b718ed4695508c2a9d4a3248ead7"
1243-
integrity sha512-5ttHGE75Nw9/l5S8zR2xEwR8OHEqcpPym3idIMAZ2yo+Edk0W/Vf46jGqPOZDk+m/SJ+vYZDSuztzhVha8rcdA==
1244-
1245-
"@next/swc-darwin-x64@15.1.5":
1246-
version "15.1.5"
1247-
resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-15.1.5.tgz#362fa82504ee496af0e7364d8383585f504a03de"
1248-
integrity sha512-8YnZn7vDURUUTInfOcU5l0UWplZGBqUlzvqKKUFceM11SzfNEz7E28E1Arn4/FsOf90b1Nopboy7i7ufc4jXag==
1249-
1250-
"@next/swc-linux-arm64-gnu@15.1.5":
1251-
version "15.1.5"
1252-
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.1.5.tgz#34bd054f222f45d7b3f5887cc2be3fe87b69e6a5"
1253-
integrity sha512-rDJC4ctlYbK27tCyFUhgIv8o7miHNlpCjb2XXfTLQszwAUOSbcMN9q2y3urSrrRCyGVOd9ZR9a4S45dRh6JF3A==
1254-
1255-
"@next/swc-linux-arm64-musl@15.1.5":
1256-
version "15.1.5"
1257-
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.1.5.tgz#125356cf3e0a9c90e32383e462d14790a6a40763"
1258-
integrity sha512-FG5RApf4Gu+J+pHUQxXPM81oORZrKBYKUaBTylEIQ6Lz17hKVDsLbSXInfXM0giclvXbyiLXjTv42sQMATmZ0A==
1259-
1260-
"@next/swc-linux-x64-gnu@15.1.5":
1261-
version "15.1.5"
1262-
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.1.5.tgz#1dc8bf2374b5f3384370ef97e4b3bbead73b250c"
1263-
integrity sha512-NX2Ar3BCquAOYpnoYNcKz14eH03XuF7SmSlPzTSSU4PJe7+gelAjxo3Y7F2m8+hLT8ZkkqElawBp7SWBdzwqQw==
1264-
1265-
"@next/swc-linux-x64-musl@15.1.5":
1266-
version "15.1.5"
1267-
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.1.5.tgz#45dc68da9e1f22de4ef37d397aeb9cf40746871d"
1268-
integrity sha512-EQgqMiNu3mrV5eQHOIgeuh6GB5UU57tu17iFnLfBEhYfiOfyK+vleYKh2dkRVkV6ayx3eSqbIYgE7J7na4hhcA==
1269-
1270-
"@next/swc-win32-arm64-msvc@15.1.5":
1271-
version "15.1.5"
1272-
resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.1.5.tgz#ce51388f07b9f0f0e1d4f22dcbba75bcca1952fa"
1273-
integrity sha512-HPULzqR/VqryQZbZME8HJE3jNFmTGcp+uRMHabFbQl63TtDPm+oCXAz3q8XyGv2AoihwNApVlur9Up7rXWRcjg==
1274-
1275-
"@next/swc-win32-x64-msvc@15.1.5":
1276-
version "15.1.5"
1277-
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.1.5.tgz#43135b3d9705ae8e6a6b90c8bdf4dc02b9ffc90c"
1278-
integrity sha512-n74fUb/Ka1dZSVYfjwQ+nSJ+ifUff7jGurFcTuJNKZmI62FFOxQXUYit/uZXPTj2cirm1rvGWHG2GhbSol5Ikw==
1240+
"@next/swc-darwin-arm64@15.2.0-canary.33":
1241+
version "15.2.0-canary.33"
1242+
resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.2.0-canary.33.tgz#946b9fa766575baf7577ea21b70105d5fefc86ed"
1243+
integrity sha512-+fCdK2KmR6lWoCTk1fSd5pvbiLZHfZF+D/Xdz3xrXw+pbnBtXWLKQrPT0bCtDseMxD31qcOywq5mAApvI3EGpA==
1244+
1245+
"@next/swc-darwin-x64@15.2.0-canary.33":
1246+
version "15.2.0-canary.33"
1247+
resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-15.2.0-canary.33.tgz#8878b319cd3d3f90648097d5d76b54b1db02d4f0"
1248+
integrity sha512-GrrU+tSmeBRow+7bnn7i5M96g3tc28hPH5t5Y65qUXGmmrZwGZN1e1d+8QbXPdAGkvjEPcOkUNQuQVpp1qpYPA==
1249+
1250+
"@next/swc-linux-arm64-gnu@15.2.0-canary.33":
1251+
version "15.2.0-canary.33"
1252+
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.2.0-canary.33.tgz#0bc4f61ccbb4e7424f9acb215f0d7e0674456f5e"
1253+
integrity sha512-8RnGxnUpASHoUf6aHUifmZom5b4Ow5nTdCib/CNYXZ6VLuL5ocvmr+DXs/SKzi9h8OHR7JkLwKXHCcF8WyscSg==
1254+
1255+
"@next/swc-linux-arm64-musl@15.2.0-canary.33":
1256+
version "15.2.0-canary.33"
1257+
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.2.0-canary.33.tgz#15fa3982f382dc6c51ac17d47111b6525deb7f94"
1258+
integrity sha512-COyE0LzMuLBZSR+Z/TOGilyJPdwSU588Vt0+o8GoECkoDEnjyuO2s2nHa2kDAcEfUEPkhlo0tErU3mF+8AVOTQ==
1259+
1260+
"@next/swc-linux-x64-gnu@15.2.0-canary.33":
1261+
version "15.2.0-canary.33"
1262+
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.2.0-canary.33.tgz#94d06dcb6f116c470d9d6a7ddda0a29ab23ce80b"
1263+
integrity sha512-3Y9lqJs+ftU9jgbLdCtvAvF8MNJsJYGMH7icb8QMs1+yOyHHbmwkZoElKdjwfUWzQ2sX28ywp73GWq4HbrsoUg==
1264+
1265+
"@next/swc-linux-x64-musl@15.2.0-canary.33":
1266+
version "15.2.0-canary.33"
1267+
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.2.0-canary.33.tgz#daaa3610648afe7440f3672d11352ecd5109d2df"
1268+
integrity sha512-FS9iA+RkZlhdWGQEKtsplVBXIYZJUn5nsRB+1UY46b3uaL6dDypu13ODaSwYuAwXGgkrZBVF9AFO3y4biBnPlA==
1269+
1270+
"@next/swc-win32-arm64-msvc@15.2.0-canary.33":
1271+
version "15.2.0-canary.33"
1272+
resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.2.0-canary.33.tgz#e704113f42449f30ee0d81337ff9c27177cad75c"
1273+
integrity sha512-Ji9CtBbUx06qvvN/rPohJN2FEFGsUv26F50f2nMRYRwrq3POXDjloGOiRocrjU0ty/cUzCz71qTUfKdmv/ajmg==
1274+
1275+
"@next/swc-win32-x64-msvc@15.2.0-canary.33":
1276+
version "15.2.0-canary.33"
1277+
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.2.0-canary.33.tgz#d719ea46ba61f3a97678dd0b290147488ea974ba"
1278+
integrity sha512-hjdbGnkwIZ8zN2vlS6lNsEJO37HRtcEGimzfkruBMsi/DwJBqkJvZbNC/XCJy3HFcU58igncqV52p1IPjmAJAw==
12791279

12801280
"@nodelib/[email protected]":
12811281
version "2.1.5"
@@ -2522,6 +2522,13 @@ chokidar@^3.4.0, chokidar@^3.5.3:
25222522
optionalDependencies:
25232523
fsevents "~2.3.2"
25242524

2525+
chokidar@^4.0.3:
2526+
version "4.0.3"
2527+
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-4.0.3.tgz#7be37a4c03c9aee1ecfe862a4a23b2c70c205d30"
2528+
integrity sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==
2529+
dependencies:
2530+
readdirp "^4.0.1"
2531+
25252532
ci-info@^3.2.0:
25262533
version "3.3.0"
25272534
resolved "https://registry.npmjs.org/ci-info/-/ci-info-3.3.0.tgz"
@@ -5805,27 +5812,27 @@ next-tick@^1.1.0:
58055812
resolved "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz"
58065813
integrity sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==
58075814

5808-
next@^15.1.5:
5809-
version "15.1.5"
5810-
resolved "https://registry.yarnpkg.com/next/-/next-15.1.5.tgz#80972a606d17ead86323d3405abf3bd3e2c894c8"
5811-
integrity sha512-Cf/TEegnt01hn3Hoywh6N8fvkhbOuChO4wFje24+a86wKOubgVaWkDqxGVgoWlz2Hp9luMJ9zw3epftujdnUOg==
5815+
next@^15.2.0-canary.33:
5816+
version "15.2.0-canary.33"
5817+
resolved "https://registry.yarnpkg.com/next/-/next-15.2.0-canary.33.tgz#a866edb669618a5a7aac5035895255eb0c9fb189"
5818+
integrity sha512-WF8QLeYkakuYwksdWY/F+Bi8tNJfIbiSYk9hCmldn9sNp1lU3lqI1hrW1ynbcMSaXC+qQEr7yol2OdvVZ4nZYQ==
58125819
dependencies:
5813-
"@next/env" "15.1.5"
5820+
"@next/env" "15.2.0-canary.33"
58145821
"@swc/counter" "0.1.3"
58155822
"@swc/helpers" "0.5.15"
58165823
busboy "1.6.0"
58175824
caniuse-lite "^1.0.30001579"
58185825
postcss "8.4.31"
58195826
styled-jsx "5.1.6"
58205827
optionalDependencies:
5821-
"@next/swc-darwin-arm64" "15.1.5"
5822-
"@next/swc-darwin-x64" "15.1.5"
5823-
"@next/swc-linux-arm64-gnu" "15.1.5"
5824-
"@next/swc-linux-arm64-musl" "15.1.5"
5825-
"@next/swc-linux-x64-gnu" "15.1.5"
5826-
"@next/swc-linux-x64-musl" "15.1.5"
5827-
"@next/swc-win32-arm64-msvc" "15.1.5"
5828-
"@next/swc-win32-x64-msvc" "15.1.5"
5828+
"@next/swc-darwin-arm64" "15.2.0-canary.33"
5829+
"@next/swc-darwin-x64" "15.2.0-canary.33"
5830+
"@next/swc-linux-arm64-gnu" "15.2.0-canary.33"
5831+
"@next/swc-linux-arm64-musl" "15.2.0-canary.33"
5832+
"@next/swc-linux-x64-gnu" "15.2.0-canary.33"
5833+
"@next/swc-linux-x64-musl" "15.2.0-canary.33"
5834+
"@next/swc-win32-arm64-msvc" "15.2.0-canary.33"
5835+
"@next/swc-win32-x64-msvc" "15.2.0-canary.33"
58295836
sharp "^0.33.5"
58305837

58315838
nice-try@^1.0.4:
@@ -6807,6 +6814,11 @@ read-pkg@^3.0.0:
68076814
normalize-package-data "^2.3.2"
68086815
path-type "^3.0.0"
68096816

6817+
readdirp@^4.0.1:
6818+
version "4.1.1"
6819+
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-4.1.1.tgz#bd115327129672dc47f87408f05df9bd9ca3ef55"
6820+
integrity sha512-h80JrZu/MHUZCyHu5ciuoI0+WxsCxzxJTILn6Fs8rxSnFPh+UVHYfeIxK1nVGugMqkfC4vJcBOYbkfkwYK0+gw==
6821+
68106822
readdirp@~3.6.0:
68116823
version "3.6.0"
68126824
resolved "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz"

0 commit comments

Comments
 (0)