0
0
NextJSframework~10 mins

Client-only modules in NextJS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Client-only modules
Start Next.js App
Import Client-only Module
Check Execution Environment
Server
Skip
Render Page
Display Client-only Features
Next.js checks if code runs on server or client. Client-only modules load and run only in the browser, skipping server rendering.
Execution Sample
NextJS
import dynamic from 'next/dynamic';

const ClientOnlyComponent = dynamic(() => import('./ClientOnlyComponent'), { ssr: false });

export default function Page() {
  return <ClientOnlyComponent />;
}
This code imports a component only on the client side, disabling server-side rendering for it.
Execution Table
StepActionEnvironmentResultRendered Output
1Start app and import dynamicServerModule imported, no client-only loaded yetPage starts rendering
2Evaluate dynamic import with ssr:falseServerSkip loading ClientOnlyComponentPlaceholder or empty space rendered
3Render page on serverServerPage rendered without ClientOnlyComponentPage HTML without client-only content
4Send HTML to browserClientBrowser receives HTMLPage visible but client-only part missing
5Browser runs JS, triggers dynamic importClientClientOnlyComponent loaded and executedClient-only content appears
6User sees full page with client-only featuresClientClient-only module activeFull interactive page displayed
7End--Execution complete
💡 Client-only module is not loaded on server (ssr:false), loads only in browser after initial HTML render
Variable Tracker
VariableStartAfter Step 2After Step 5Final
ClientOnlyComponentundefinedundefined (skipped on server)Loaded componentLoaded component
Key Moments - 2 Insights
Why does the ClientOnlyComponent not appear in the server-rendered HTML?
Because the dynamic import uses { ssr: false }, Next.js skips loading this module on the server as shown in execution_table step 2, so it doesn't render on the server.
When does the ClientOnlyComponent actually load and render?
It loads only in the browser after the initial HTML is sent, as shown in execution_table step 5, when the client runs the JavaScript and dynamically imports the module.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the ClientOnlyComponent first become loaded?
AStep 5
BStep 3
CStep 2
DStep 1
💡 Hint
Check the 'Result' column for when ClientOnlyComponent is 'Loaded component'
According to variable_tracker, what is the value of ClientOnlyComponent after step 2?
ALoaded component
Bnull
Cundefined (skipped on server)
DError
💡 Hint
Look at the 'After Step 2' column for ClientOnlyComponent in variable_tracker
If we remove { ssr: false } from dynamic import, what changes in the execution_table?
AClientOnlyComponent never loads
BClientOnlyComponent loads on server and client
CClientOnlyComponent loads only on client as before
DPage fails to render
💡 Hint
Removing ssr:false means server tries to load the module, check step 2 behavior
Concept Snapshot
Client-only modules in Next.js load only in the browser.
Use dynamic import with { ssr: false } to skip server rendering.
Server renders page without client-only parts.
Client loads and runs module after initial HTML.
This avoids server errors from browser-only code.
Full Transcript
In Next.js, client-only modules are loaded only in the browser, not on the server. This is done by using dynamic imports with the option ssr:false. When the app starts, Next.js imports modules but skips client-only ones during server rendering. The server sends HTML without the client-only parts. When the browser receives the page, it runs JavaScript that dynamically loads and runs the client-only modules. This way, browser-specific code does not break server rendering. The execution table shows these steps clearly, with the client-only component undefined on the server and loaded on the client. The variable tracker confirms the component is undefined on the server and loaded later in the browser. This pattern helps keep Next.js apps stable and interactive.