Hint: Suspense needs fallback prop and closing tag [OK]
Common Mistakes:
Forgetting to close Suspense tag
Passing fallback inside child component
Using fallback as string with JSX tags
3. Given this Next.js component using streaming with Suspense:
import { Suspense } from 'react';
function SlowComponent() {
return
Data loaded
;
}
export default function Page() {
return (
Loading...
}>
);
}
What will the user see first when this page loads?
medium
A. An error because Suspense cannot be used here
B. The text 'Loading...' immediately, then 'Data loaded' after SlowComponent finishes
C. A blank page until SlowComponent loads
D. Only 'Data loaded' without any loading text
Solution
Step 1: Check if SlowComponent suspends
SlowComponent is synchronous and returns <div>Data loaded</div> immediately without throwing a promise, so Suspense does not trigger fallback.
Step 2: Determine initial render behavior
The entire page renders instantly with 'Data loaded' inside the div. No fallback appears because there is no suspension.
Final Answer:
Only 'Data loaded' without any loading text -> Option D
Quick Check:
No suspend = no fallback, direct content render [OK]
Hint: Suspense fallback only if children suspend (throw promise) [OK]
Common Mistakes:
Assuming Suspense always shows fallback
Thinking synchronous components trigger loading
Expecting streaming without suspend mechanism
4. Identify the error in this Next.js streaming code snippet:
import { Suspense } from 'react';
export default function Page() {
return (
<div>
<Suspense fallback="Loading...">
<SlowComponent />
</Suspense>
</div>
);
}
function SlowComponent() {
throw new Promise(resolve => setTimeout(resolve, 1000));
return <div>Loaded</div>;
}
medium
A. The return statement after throw is unreachable
B. SlowComponent cannot throw a Promise
C. The fallback prop should be a React node, not a string
D. Suspense must be imported from 'next/suspense' not 'react'
Solution
Step 1: Spot unreachable code
The return <div>Loaded</div> after throw is unreachable because the throw executes first.
Step 2: Validate other parts
Import from 'react' is correct; throwing a Promise suspends correctly (though recreating it causes infinite loop here); fallback string is valid ReactNode.
Final Answer:
The return statement after throw is unreachable -> Option A
Quick Check:
throw before return = unreachable [OK]
Hint: Code after throw is unreachable [OK]
Common Mistakes:
Thinking fallback string causes issues
Believing components cannot throw Promises
Wrong import source for Suspense
5. You want to stream two slow components in Next.js with Suspense, showing their fallbacks independently. Which approach correctly achieves this?
hard
A. <Suspense fallback="Loading..."><ComponentA /></Suspense><ComponentB fallback="Loading B..." />
B. <Suspense fallback="Loading A..."><ComponentA /></Suspense><Suspense fallback="Loading B..."><ComponentB /></Suspense>
C. <ComponentA /><ComponentB /> without Suspense
D. <Suspense fallback="Loading A and B..."><ComponentA /><ComponentB /></Suspense>
Wrapping each slow component in its own Suspense allows each to show its own fallback independently.
Step 2: Analyze options
<Suspense fallback="Loading A..."><ComponentA /></Suspense><Suspense fallback="Loading B..."><ComponentB /></Suspense> wraps each component separately with distinct fallbacks, enabling independent streaming. <Suspense fallback="Loading A and B..."><ComponentA /><ComponentB /></Suspense> shares one fallback for both, so they load together. <ComponentA /><ComponentB /> without Suspense has no fallback. <Suspense fallback="Loading..."><ComponentA /></Suspense><ComponentB fallback="Loading B..." /> incorrectly uses fallback on a component.
Final Answer:
<Suspense fallback="Loading A..."><ComponentA /></Suspense><Suspense fallback="Loading B..."><ComponentB /></Suspense> -> Option B
Quick Check:
Separate Suspense per component = independent fallbacks [OK]
Hint: Wrap each slow component in its own Suspense [OK]
Common Mistakes:
Using one Suspense for multiple components expecting separate fallbacks