Skip to content

Commit

Permalink
fix: 초기 렌더링 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
ienrum committed Apr 24, 2024
1 parent 699136d commit f618a5d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export async function register() {
);

if (process.env.NEXT_RUNTIME === 'nodejs') {
console.log('MOCKING ENABLED FOR:', process.pid);

const { server } = await import('@/src/mocks/node');
server.listen();
server.listen({
onUnhandledRequest: 'bypass',
});
}
}
3 changes: 1 addition & 2 deletions src/mocks/MSWComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export const MSWComponent = ({ children }: { children: React.ReactNode }) => {

useEffect(() => {
if (!isInit) {
initMsw();
isSetInit(true);
initMsw().then(() => isSetInit(true));
}
}, [isInit]);

Expand Down
2 changes: 1 addition & 1 deletion src/mocks/handlers/post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpResponse, http } from 'msw';

const getPostList = http.get(`${process.env.NEXT_DOMAIN}/posts`, () => {
const getPostList = http.get(`${process.env.NEXT_PUBLIC_URL}/posts`, () => {
return HttpResponse.json({
content: [
{
Expand Down
23 changes: 6 additions & 17 deletions src/mocks/initMsw.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
export const initMsw = () => {
if (process.env.NODE_ENV === 'development') {
if (process.env.NEXT_RUNTIME === 'nodejs') {
(async () => {
const { server } = await import('./node');
server.listen({
onUnhandledRequest: 'bypass',
});
})();
} else {
(async () => {
const { worker } = await import('./browser');
worker.start({
onUnhandledRequest: 'bypass',
});
})();
}
export const initMsw = async () => {
if (process.env.NEXT_RUNTIME !== 'nodejs') {
const { worker } = await import('./browser');
await worker.start({
onUnhandledRequest: 'bypass',
});
}
};

0 comments on commit f618a5d

Please sign in to comment.