inflearn logo
강의

Course

Instructor

[Renewal] Creating a NodeBird SNS with React

Q&A before distribution

css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.

283

dydcodydco0983

40 asked

0

https://www.inflearn.com/course/lecture?courseSlug=%EB%85%B8%EB%93%9C%EB%B2%84%EB%93%9C-%EB%A6%AC%EC%95%A1%ED%8A%B8-%EB%A6%AC%EB%89%B4%EC%96%BC&unitId=49018&category=questionDetail&tab=community&q=1075492

안녕하세요 제로초님!

위의 질문 답변을 보고 css 서버사이드 랜더링을 하기위해서 이것저것 해보았는데 적용이 안되서 문의 드립니다.

  1. .babelrc 작성

  2. next.config.js에서도 옵션으로 가능하다고해서 수정

  3. _document.js 수정

  4. 빌드 하고 npm start하고 테스트

  5. 위 링크의 답변 참고해서

    @ant-design/cssinjs 적용해봄

     

     

그럼에도 적용안되더라구요 ㅠ

pages/_docuemnts.js
(이 전에는 제로초님깃헙의 것을 썼었습니다. 안돼서 @ant-design/cssinjs 적용한 버전입니다.

import React from "react";
import Document, { Html, Head, Main, NextScript } from "next/document";
import { createCache, extractStyle, StyleProvider } from "@ant-design/cssinjs";
import { ServerStyleSheet } from "styled-components";

export default class MyDocument extends Document {
	static async getInitialProps(ctx) {
		const cache = createCache();
		const sheet = new ServerStyleSheet();
		const originalRenderPage = ctx.renderPage;
		try {
			ctx.renderPage = () =>
				originalRenderPage({
					enhanceApp: (App) => (props) =>
						(
							<StyleProvider cache={cache}>
								<App {...props} />
							</StyleProvider>
						),
				});
			const initialProps = await Document.getInitialProps(ctx);
			const style = extractStyle(cache, true);
			return {
				...initialProps,
				styles: (
					<>
						{initialProps.styles}
						<style dangerouslySetInnerHTML={{ __html: style }} />
					</>
				),
			};
		} catch (error) {
			console.error(error);
		} finally {
			sheet.seal();
		}
	}

	render() {
		return (
			<Html>
				<Head />
				<body>
					<Main />
					<NextScript />
				</body>
			</Html>
		);
	}
}

 

next.config.js

const withBundleAnalyzer = require("@next/bundle-analyzer")({
	enabled: process.env.ANALYZE === "true",
});

module.exports = withBundleAnalyzer({
	images: {
		domains: ["react-nodebird.s3.ap-northeast-2.amazonaws.com", "react-nodebird-s3.s3.amazonaws.com"],
	},
	compress: true,
	compiler: {
		styledComponents: {
			ssr: true,
			displayName: true,
		},
	},
	webpack(config, { webpack }) {
		const prod = process.env.NODE_ENV === "production";
		return {
			...config,
			mode: prod ? "production" : "development",
			devtool: prod ? "hidden-source-map" : "inline-source-map",
			plugins: [...config.plugins],
		};
	},
});

.eslintrc

{
	"parser": "@babel/eslint-parser", 
	"parserOptions": {
		"ecmaVersion": "latest", 
		"sourceType": "module", 
		"ecmaFeatures": {
			"jsx": true
		},
		"requireConfigFile": false,
		"babelOptions": {
			"presets": ["next/babel"]
		}
	},
	"env": {
		"browser": true,
		"node": true,
		"es6": true
	},
	"extends": [
		"airbnb", 
		"next/babel"
	], 
	"plugins": ["import", "react-hooks", "jsx-a11y"],
	"rules": {
		"react/react-in-jsx-scope": "off",
		"jsx-a11y/label-has-associated-control": "off",
		"jsx-a11y/anchor-is-valid": "off",
		"no-console": "off",
		"no-underscore-dangle": "off",
		"react/forbid-prop-types": "off",
		"react/jsx-filename-extension": "off",
		"react/jsx-one-expression-per-line": "off",
		"react/jsx-props-no-spreading": "off",
		"object-curly-newline": "off",
		"linebreak-style": "off",
		"no-param-reassign": "off",
		"max-len": "off"
	}
}

/.babelrc

{
	"presets": ["next/babel"],
	"plugins": [
		[
			"styled-components",
			{
				"ssr": true,
				"displayName": true
			}
		]
	]
}

https://github.com/dydcodydco/react-nodebird
혹시나해서 깃헙 주소도 남깁니다.

마지막으로 하나 더 궁금한게 있습니다.
이 강의를 내껄로 만들고, 다음강의 슬랙까지 강의보고 하면

중고신입으로 개발자 이직할 수 있을지도 궁금합니다.
좋은 강의 정말 감사합니다.

react redux node.js express next.js

Answer 1

0

zerocho

이건 antd 가이드 따라할 수밖에 없어서 더 도움드릴 수가 없습니다. 일단 저는 잘 나와서요.

요즘같은 취업 시장에서는 제 강의를 보는 정도만으로는 어렵고, 개발 시 생기는 문제를 스스로 거의 다 해결할 수 있는 정도의 실력이 되어야 가능한 것 같습니다. 요즘 좀 많이 어렵습니다.

0

dydcodydco0983

답변 감사합니다!

넥스트 버젼 질문

0

75

2

로그인시 401 Unauthorized 오류가 뜹니다

0

88

1

무한 스크롤 중 스크롤 튐 현상

0

172

1

특정 페이지 접근을 막고 싶을 때

0

103

2

createGlobalStyle의 위치와 영향범위

0

93

2

인라인 스타일 리렌더링 관련

0

90

2

vsc 에서 npm init 설치시 오류

0

146

2

nextjs 15버전 사용 가능할까요?

0

158

1

화면 새로고침 문의

0

119

1

RTK에서 draft, state 차이가 있나요?

0

151

2

Next 14 사용해도 될까요?

0

452

1

next, node 버전 / 폴더 구조 질문 드립니다.

0

348

1

url 오류 질문있습니다

0

210

1

ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out

0

372

1

sudo certbot --nginx 에러

0

1271

2

Minified React error 콘솔에러 (hydrate)

0

467

1

카카오 공유했을 때 이전에 작성했던 글이 나오는 버그

0

245

1

프론트서버 배포 후 EADDRINUSE에러 발생

0

325

1

npm run build 에러

0

517

1

front 서버 npm run build 중에 발생한 에러들

0

381

1

서버 실행하고 브라우저로 들어갔을때 404에러

0

335

2

팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.

0

235

2

해시태그 검색에서 throttle에 관해 질문있습니다.

0

198

1

full reload 될때는 서버 데이터를 호출하는데 그 이후로 새로고침할대는 호출하지 않아서 답답합니다

0

289

2