Skip to content

[react-pdf] 첫 렌더 시 페이지가 컨테이너보다 넓게 그려지는 문제 수정 - #230

Merged
2-one-week merged 1 commit into
mainfrom
fix/react-pdf-initial-page-width
Oct 21, 2026
Merged

2-one-week merged 1 commit into
mainfrom
fix/react-pdf-initial-page-width

Conversation

@2-one-week

Copy link
Copy Markdown
Member

Related Issue

Describe your changes

  • maxPageWidth={768}, 감싼 영역 768px, 창 폭 1439px인 환경에서 첫 로드 시 canvas가 768px로 그려져 .document(754px)보다 넓게 렌더링되는 문제가 있었습니다. (창 크기 변경 후에는 754px로 정상)
  • 원인: width가 계산되기 전에는 PdfViewer가 null을 반환해 ref가 연결된 div가 마운트되지 않습니다. 그래서 첫 측정 시 refElement.current가 없어 window.innerWidth(1439)로 fallback되고, min(1439 - 14, 768) = 768이 됩니다.
  • 수정: 로딩 중에도 ref를 연결한 빈 div(style 동일 적용)를 렌더링해, 첫 측정부터 컨테이너 폭(768 - 14 = 754) 기준으로 계산되도록 합니다.

Request

  • 로딩 중 placeholder div는 높이 0이라 레이아웃에 영향이 없습니다.
  • 버그 수정이라 changeset은 patch로 지정했습니다.

@2-one-week
2-one-week requested a review from a team as a code owner October 20, 2026 10:40
@2-one-week

Copy link
Copy Markdown
Member Author

/canary-publish

@npayfebot

Copy link
Copy Markdown
Collaborator

✅ Changeset detected

Latest commit: 459df2f

@naverpay/react-pdf package have detected changes.

If no version change is needed, please add skip-detect-change to the label.

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@naverpay/react-pdf 🐛 Patch
powered by: naverpay changeset detect-add actions

@npayfebot

Copy link
Copy Markdown
Collaborator

🔍 No files have been changed

Latest commit: 459df2f

Please check your commit.

powered by: naverpay size-action

@2-one-week
2-one-week enabled auto-merge October 21, 2026 06:22

@myamaak myamaak left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

@2-one-week
2-one-week disabled auto-merge October 21, 2026 06:35
@2-one-week
2-one-week merged commit 503fe2e into main Oct 21, 2026
8 checks passed
@2-one-week
2-one-week deleted the fix/react-pdf-initial-page-width branch October 21, 2026 06:35
return null
/* 첫 렌더에서도 컨테이너 폭을 측정할 수 있도록 높이 0인 div에 ref를 연결한다.
* ref가 없으면 window.innerWidth로 계산되어 컨테이너보다 넓게 그려진다. */
return <div ref={ref} style={style} />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

className={cx('article')} 까지 포함될 필요는 없을까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네네 괜찮을 것 같습니다! 기존 동작이 null 이였어서 article 넣으면 min-height : 100% 때문에 로딩중에 회색 부분 보일 것 같습니다..!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants