
Security News
curl Shuts Down Bug Bounty Program After Flood of AI Slop Reports
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.
next-client-script
Advanced tools
Supercharge the performance of your Next.js apps by using a minimal client runtime that avoids full-blown hydration. 🚀
By default, Next.js adds the code to your client bundle that is necessary to execute your whole page. At a minimum this includes React itself, the components to render the markup and if relevant, the data that is necessary to rehydrate the markup (result from getInitialProps and friends).
For content heavy sites this can cause performance issues since the page is unresponsive while the client bundle is being executed.
Recently, an early version of removing the client side bundle was shipped to Next.js which doesn't suffer from performance problems caused by hydration. However, for a typical website you'll likely still need some JavaScript on the client side to deliver a reasonable user experience.
This is a Next.js plugin that is intended to be used in conjunction with disabled runtime JavaScript. You can add client bundles on a per-page basis that only sprinkle a tiny bit of JavaScript over otherwise completely static pages.
This allows for the same architecture that Netflix has chosen for their public pages.
Benefits:
The tradeoff is that you can't use any client-side features of React (state, effects, event handlers, …). Note that some features of Next.js might not be available (yet) – e.g. code splitting via dynamic within a page.
→ Demo deployment (source)
⚠️ Important: To achieve the desired effect, this plugin modifies the webpack configuration that Next.js consumes. Similar as with other Next.js plugins, it's possible that this plugin will break when there are updates to Next.js. I'm keeping the plugin updated so that it continues to work with new versions of Next.js.
| Next.js version | Plugin version |
|---|---|
| ^9.5.0 | 0.1.0 |
| ^9.4.0 | 0.0.6 |
Latest version tested: 9.5.2
// ./src/client/index.ts
console.log('Hello from client.');
next.config.js and reference your client script.const withClientScripts = require('next-client-script/withClientScripts');
// Define which paths will cause which scripts to load
module.exports = withClientScripts({
'/': './src/client/index.ts',
// You can use parameters as provided by path-to-regexp to match routes dynamically.
'/products/:id': './src/client/product.ts'
})();
<ClientScript /> component as the last child in the body.+ import ClientScript from 'next-client-script/ClientScript';
// ...
+ <ClientScript />
</body>
// ./pages/index.ts
export const config = {
unstable_runtimeJS: false
};
Note that you can mix this approach with the traditional hydration approach, to optimize the performance of critical pages while keeping the flexibility of using React on the client side for other pages.
See the example folder for a project demonstrating this setup.
To help with a component-oriented approach for client-side code, this library contains convenience APIs that help with passing data to the client and initializing widgets.
Use the ClientWidget component to mark an entry point for the client side and to optionally pass in some data.
// Counter.js
import ClientWidget from 'next-client-script/ClientWidget';
import styles from './Counter.module.scss';
export default function Counter({initialCount = 2}) {
return (
<ClientWidget className={styles.root} data={{initialCount}}>
<p className={styles.label}>
Count: <span className={styles.count}>{initialCount}</span>
</p>
<button className={styles.button}>Increment</button>
</ClientWidget>
);
}
Now you can add a client part for this component that receives the data and adds interactivity.
// Counter.client.js
import styles from './Counter.module.scss';
export default function initCounter(rootNode, data) {
let count = data.initialCount;
const countNode = rootNode.querySelector(`.${styles.count}`);
const buttonNode = rootNode.querySelector(`.${styles.button}`);
buttonNode.addEventListener('click', () => {
count++;
countNode.textContent = count;
});
}
// This will be passed to `querySelectorAll` to find all widgets on the page
initCounter.selector = `.${styles.root}`;
As a last step, you need to reference the client counter code in your client script:
import initWidgets from 'next-client-script/initWidgets';
import Counter from 'components/Counter/Counter.client';
initWidgets([Counter]);
I really hope that React will solve hydration problems in the future with partial hydration and server-side components, but I think a tiny bit of vanilla JavaScript on the client side is really hard to beat.
FAQs
Add a separate client entry point to your Next.js pages.
We found that next-client-script demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A surge of AI-generated vulnerability reports has pushed open source maintainers to rethink bug bounties and tighten security disclosure processes.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.