Skip to content

fix(warn): Optimize console warnings to prevent excessive output in development #2661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2025

Conversation

sungik-choi
Copy link
Contributor

@sungik-choi sungik-choi commented Jul 3, 2025

Self Checklist

  • I wrote a PR title in English and added an appropriate label to the PR.
  • I wrote the commit message in English and to follow the Conventional Commits specification.
  • I added the changeset about the changes that needed to be released. (or didn't have to)
  • I wrote or updated documentation related to the changes. (or didn't have to)
  • I wrote or updated tests related to the changes. (or didn't have to)
  • I tested the changes in various browsers. (or didn't have to)
    • Windows: Chrome, Edge, (Optional) Firefox
    • macOS: Chrome, Edge, Safari, (Optional) Firefox

Related Issue

Summary

Optimizes the warn utility function to prevent excessive console warnings in development mode, specifically addressing performance issues when many components trigger the same warning (e.g., legacy icon deprecation).

Details

This PR introduces a scope parameter to the warn function. When a scope is provided, the warning message for that specific scope will only be logged to the console once per development session.

This change was made to:

  • Prevent UI blocking and developer tool freezing caused by hundreds or thousands of identical console warnings, especially when using components with deprecated features (like legacy icons) in large lists.
  • Improve the developer experience by reducing console noise while still providing necessary warnings.

Key Changes:

  • packages/bezier-react/src/utils/assert.ts:
    • warn function overloaded to accept an optional scope string.
    • Uses an internal Set (devWarningScopes) to track and ensure each scoped warning is logged only once.
  • Component Updates:
    • Applied the new scope parameter to existing legacy icon deprecation warnings in Button, Banner, and SectionLabel components.
  • Test Coverage:
    • Added new tests for the warn function to verify that warnings are logged only once per scope and that different scopes are handled independently.

Breaking change? (Yes/No)

No. This is an internal utility improvement that only affects development-mode console output.

References

Summary by CodeRabbit

Summary by CodeRabbit

  • 신규 기능

    • 경고 메시지에 scope(범위) 파라미터가 추가되어, 동일 범위 내에서는 경고가 한 번만 표시됩니다.
  • 버그 수정

    • Button, Banner, SectionLabel 컴포넌트의 레거시 아이콘 사용 시 과도한 경고로 인한 UI 지연 현상이 개선되었습니다.
  • 테스트

    • scope별 경고 동작을 검증하는 테스트가 추가되었습니다.

@sungik-choi sungik-choi requested a review from yangwooseong as a code owner July 3, 2025 02:46
Copy link

changeset-bot bot commented Jul 3, 2025

🦋 Changeset detected

Latest commit: c4bd514

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

This PR includes changesets to release 2 packages
Name Type
@channel.io/bezier-react Patch
bezier-figma-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

channeltalk bot commented Jul 3, 2025

Copy link

coderabbitai bot commented Jul 3, 2025

"""

Walkthrough

이 변경사항은 warn 함수에 scope 파라미터를 추가하여, 동일한 스코프 내에서는 경고 메시지가 한 번만 출력되도록 최적화했습니다. 이 기능은 Button, Banner, SectionLabel 컴포넌트의 레거시 아이콘 사용 경고에 적용되었고, 새로운 동작을 검증하는 테스트도 추가되었습니다.

Changes

파일/경로 변경 요약
packages/bezier-react/src/utils/assert.ts warn 함수에 선택적 scope 파라미터 추가, 스코프별 1회 경고 로직 및 시그니처 오버로드
packages/bezier-react/src/components/Button/Button.tsx warn 호출 시 'Button.IconName' 스코프 문자열 추가
packages/bezier-react/src/components/Banner/Banner.tsx warn 호출 시 'Banner.IconName' 스코프 문자열 추가
packages/bezier-react/src/components/SectionLabel/SectionLabel.tsx warn 호출 시 각각 'SectionLabel.LeftContent.IconName''SectionLabel.RightContent.IconName' 스코프 문자열 추가
packages/bezier-react/src/utils/assert.test.ts warn의 스코프별 1회 경고 동작 및 프로덕션 환경 미출력 테스트 케이스 추가
.changeset/warn-scope-optimization.md 변경사항 요약 문서 추가

Sequence Diagram(s)

sequenceDiagram
  participant Component as Button/Banner/SectionLabel
  participant WarnUtil as warn()
  participant Console as console.warn

  Component->>WarnUtil: warn("deprecation message", "ScopeName")
  alt 개발 환경 & Scope 미사용
    WarnUtil->>Console: console.warn("deprecation message")
  else 개발 환경 & Scope 최초 호출
    WarnUtil->>Console: console.warn("deprecation message")
    WarnUtil->>WarnUtil: 스코프 기록
  else 개발 환경 & Scope 재호출
    WarnUtil-->>Console: (출력 없음)
  else 프로덕션 환경
    WarnUtil-->>Console: (출력 없음)
  end
Loading

Assessment against linked issues

Objective Addressed Explanation
경고 메시지를 스코프별로 한 번만 출력 (#2644)
warn 함수에 스코프 매개변수 추가 (#2644)
Button, Banner, SectionLabel 컴포넌트에 적용 (#2644)
테스트 코드 추가로 동작 검증 (#2644)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation

Poem

🐇
경고는 한 번만, 토끼가 외치네!
스코프를 나눠서, 중복은 이제 그만해.
버튼, 배너, 섹션레이블도
깔끔한 로그로 마음이 가볍네.
개발자 도구, 이제는 안 멈춰요!

"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c3fe1e and c4bd514.

📒 Files selected for processing (1)
  • .changeset/warn-scope-optimization.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/warn-scope-optimization.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Chromatic

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sungik-choi sungik-choi changed the title Fix console warnings for legacy icons fix(warn): Optimize console warnings to prevent excessive output in development Jul 3, 2025
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.26%. Comparing base (1f0c5a1) to head (c4bd514).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2661      +/-   ##
==========================================
+ Coverage   79.22%   79.26%   +0.04%     
==========================================
  Files         145      145              
  Lines        2869     2875       +6     
  Branches      920      923       +3     
==========================================
+ Hits         2273     2279       +6     
  Misses        562      562              
  Partials       34       34              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/bezier-react/src/utils/assert.ts (1)

5-5: 메모리 누수 가능성을 고려해주세요.

devWarningScopes Set이 무한정 증가할 수 있어 장기간 실행되는 개발 환경에서 메모리 누수가 발생할 수 있습니다. 개발 환경에서만 사용되므로 실제 프로덕션에는 영향이 없지만, 매우 긴 개발 세션에서는 문제가 될 수 있습니다.

WeakSet 사용을 고려하거나 주기적으로 Set을 정리하는 메커니즘을 추가할 수 있습니다:

-const devWarningScopes = new Set<string>()
+const devWarningScopes = new Set<string>()
+
+// Optional: Clear scopes periodically in very long dev sessions
+if (typeof window !== 'undefined') {
+  setInterval(() => {
+    if (devWarningScopes.size > 1000) {
+      devWarningScopes.clear()
+    }
+  }, 300000) // 5 minutes
+}
.changeset/warn-scope-optimization.md (2)

2-2: 따옴표 스타일을 통일해주세요
Changeset YAML에서 패키지 이름은 보통 이스케이프를 위해 큰따옴표(")를 사용합니다. 사소하지만 기존 파일들과 스타일을 맞추면 가독성이 좋아집니다.

-'@channel.io/bezier-react': patch
+"@channel.io/bezier-react": patch

5-11: 요약 본문 길이·형식을 간결하게 다듬으면 좋겠습니다
Changeset 첫 문장은 1-라인 요약으로만 두고, 상세 내용은 빈 줄 이후 구체적으로 적는 방식이 권장됩니다. 현재는 1-라인 요약(5행) 뒤에 다시 bullet 목록이 이어지지만, 5행 문장이 다소 길어 80자를 넘을 수 있습니다.
예)

Optimize warn function to prevent duplicate console logs

- Add `scope` parameter …
- Apply scope to …
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f0c5a1 and b07582b.

📒 Files selected for processing (6)
  • .changeset/warn-scope-optimization.md (1 hunks)
  • packages/bezier-react/src/components/Banner/Banner.tsx (1 hunks)
  • packages/bezier-react/src/components/Button/Button.tsx (1 hunks)
  • packages/bezier-react/src/components/SectionLabel/SectionLabel.tsx (2 hunks)
  • packages/bezier-react/src/utils/assert.test.ts (1 hunks)
  • packages/bezier-react/src/utils/assert.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/bezier-react/src/utils/assert.test.ts (1)
packages/bezier-react/src/utils/assert.ts (1)
  • warn (9-22)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Chromatic
  • GitHub Check: CI
🔇 Additional comments (9)
packages/bezier-react/src/utils/assert.ts (2)

7-9: 함수 오버로딩이 올바르게 구현되었습니다.

TypeScript 함수 오버로딩을 통해 scope 매개변수의 선택적 사용을 명확하게 정의했습니다. 이는 기존 코드와의 호환성을 유지하면서 새로운 기능을 추가하는 좋은 방법입니다.


10-22: 스코프 기반 경고 중복 제거 로직이 정확합니다.

구현된 로직이 올바르게 작동합니다:

  • 스코프가 제공된 경우에만 중복 제거를 수행
  • 개발 환경에서만 동작
  • 스코프별로 한 번만 경고 출력

react-window 라이브러리에서 영감을 받은 접근 방식이 적절하게 적용되었습니다.

packages/bezier-react/src/components/Button/Button.tsx (1)

66-69: 스코프 네이밍이 명확하고 일관성 있습니다.

'Button.IconName' 스코프 식별자가 컴포넌트와 경고 유형을 명확하게 나타냅니다. 이는 다른 컴포넌트들과 일관된 네이밍 패턴을 따르고 있어 디버깅과 유지보수에 도움이 됩니다.

packages/bezier-react/src/components/Banner/Banner.tsx (1)

79-82: 스코프 적용이 올바르고 일관성 있습니다.

Banner 컴포넌트에서도 동일한 스코프 네이밍 패턴('Banner.IconName')을 적용하여 Button 컴포넌트와 일관성을 유지했습니다. 레거시 아이콘 사용에 대한 경고가 적절하게 스코프화되었습니다.

packages/bezier-react/src/components/SectionLabel/SectionLabel.tsx (2)

42-45: 세밀한 스코프 구분이 적절합니다.

SectionLabel 컴포넌트의 복잡성을 고려하여 'SectionLabel.LeftContent.IconName'으로 좌측 콘텐츠와 우측 콘텐츠를 구분한 것이 적절합니다. 이는 개발자가 경고의 출처를 정확히 파악할 수 있게 도움을 줍니다.


79-82: 일관된 스코프 네이밍 패턴을 유지했습니다.

우측 콘텐츠에 대해서도 'SectionLabel.RightContent.IconName'으로 명확하게 구분하여, 전체 컴포넌트에서 일관된 스코프 네이밍 패턴을 유지했습니다.

packages/bezier-react/src/utils/assert.test.ts (3)

90-103: 스코프별 중복 제거 동작을 정확히 테스트합니다.

동일한 스코프에서 여러 번 호출해도 한 번만 경고가 출력되는지 확인하는 테스트가 정확합니다. toHaveBeenCalledTimes(1)로 정확한 호출 횟수를 검증하고 있습니다.


105-119: 서로 다른 스코프의 독립적 처리를 잘 검증합니다.

각각의 스코프가 독립적으로 처리되어 서로 다른 메시지가 모두 출력되는지 확인하는 테스트입니다. toHaveBeenNthCalledWith를 사용하여 호출 순서와 내용을 정확히 검증하고 있습니다.


121-131: 프로덕션 환경에서의 동작을 적절히 검증합니다.

스코프가 제공되어도 프로덕션 환경에서는 경고가 출력되지 않음을 확인하는 중요한 테스트입니다. 이는 성능과 보안 측면에서 필수적인 검증입니다.

@sungik-choi sungik-choi added the enhancement Issues or PR related to making existing features better label Jul 3, 2025
Copy link
Contributor

github-actions bot commented Jul 3, 2025

Chromatic Report

🚀 Congratulations! Your build was successful!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/warn-scope-optimization.md (1)

5-11: changeset 설명 톤 · 형식 통일 필요

  • 첫 번째 본문 문장(라인 5)은 Changeset 가이드라인에 따라 명령형 · 현재 시제(예: “Optimize warn…” → “Optimize warn to…” 또는 “Optimize the warn…”)로 유지하되, 마침표를 제거하면 더욱 일관됩니다.
  • Bullet(라인 7-9)의 첫 단어 대·소문자 및 띄어쓰기를 맞추면 가독성이 좋아집니다.
    예시 diff:
- Add `scope` parameter to warn function to show warnings only once per scope
- Apply scope to legacy icon deprecation warnings in Button, Banner, and SectionLabel components
- Add comprehensive test coverage for the new warn function behavior
+ Add `scope` parameter to `warn` so each message logs only once per scope
+ Apply the scoped warning to legacy-icon deprecation in Button, Banner, SectionLabel
+ Add comprehensive tests for the new `warn` behavior
  • 마지막 문단(라인 11)은 bullet 리스트로 함께 묶거나 문장부호를 통일하면 좋겠습니다.

작은 문구 수정이지만 릴리스 노트 가독성과 일관성을 높이는 데 도움이 됩니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b07582b and 6c3fe1e.

📒 Files selected for processing (1)
  • .changeset/warn-scope-optimization.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Chromatic

@sungik-choi sungik-choi merged commit 1bc025d into main Jul 3, 2025
10 checks passed
@sungik-choi sungik-choi deleted the cursor/fix-console-warnings-for-legacy-icons-eda9 branch July 3, 2025 04:41
sungik-choi pushed a commit that referenced this pull request Jul 7, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @channel.io/[email protected]

### Patch Changes

- Optimize warn function to prevent duplicate console logs
([#2661](#2661)) by
@sungik-choi

- Add `scope` parameter to `warn` so each message logs only once per
scope
- Apply the scoped warning to legacy-icon deprecation in Button, Banner,
SectionLabel
    -   Add comprehensive tests for the new `warn` behavior
- Prevent UI blocking and developer tool freezing when using legacy
icons with virtual lists

## [email protected]

### Patch Changes

-   Updated dependencies
    -   @channel.io/[email protected]


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **버그 수정**
* 레거시 아이콘이 사용된 Button, Banner, SectionLabel 컴포넌트에서 중복 경고 메시지가 콘솔에 여러 번
출력되는 현상이 개선되었습니다. 이제 각 경고 메시지는 지정된 범위(scope) 내에서 한 번만 표시되어 개발자 도구의 성능 저하
및 UI 멈춤 현상이 방지됩니다.

* **기타**
  * bezier-figma-plugin 및 @channel.io/bezier-react 패키지의 버전이 업데이트되었습니다.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues or PR related to making existing features better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show console warn only once
3 participants