-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(dev): print i18n info only once to avoid noisy logs #4810
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
base: main
Are you sure you want to change the base?
Conversation
Dev with i18n caused the info message to print on every navigation/HMR. Use global Symbol to ensure it prints once per session. Fixes shuding#4763.
🦋 Changeset detectedLatest commit: acfb028 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
@Golenspade is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
Testing NotesI've verified the fix logic locally. Due to environment constraints, I don't have before/after screenshots at this moment, but the code change is straightforward:
Maintainers can easily verify by:
Happy to add screenshots if needed - just let me know! |
✅ All Tests PassedI've completed local verification of the fix: Test Results
Key FindingsThe fix works correctly:
The 2 initial prints are from Next.js's config evaluation process and happen only once at startup, not on every navigation/HMR like before. Commands Runpnpm -w lint # ✅ Passed
pnpm -w types:check # ✅ Passed
pnpm --filter example-docs dev # ✅ i18n log appears once, no spam
NODE_ENV=production pnpm --filter example-docs build # ✅ No i18n logsReady for review! 🚀 |
Description / 描述
Fixes #4763
English:
In development mode, when Next.js i18n is enabled, the informational message about i18n configuration is printed repeatedly on every page navigation and hot module reload (HMR). This creates unnecessary terminal noise and makes it harder to spot actual warnings or errors.
中文:
在开发模式下,当启用 Next.js i18n 时,i18n 配置信息会在每次页面导航和热模块替换(HMR)时重复打印。这会产生不必要的终端噪音,使得实际的警告或错误更难发现。
Problem / 问题复现
Before fix / 修复前:
After fix / 修复后:
Solution / 解决方案
English:
logI18nOnce()helper function usingglobalThiswithSymbol.for()to track whether the message has been printedNODE_ENV === 'production')中文:
logI18nOnce()辅助函数,使用globalThis和Symbol.for()跟踪消息是否已打印NODE_ENV === 'production'时提前返回)Why
Symbol.for()? / 为什么用Symbol.for()?English:
Symbol.for()creates a symbol in the global symbol registry. Even when the module is hot-reloaded, the symbol still points to the same reference, preventing the once-flag from being reset.中文:
Symbol.for()在全局 symbol 注册表中创建符号。即使模块被热重载,symbol 仍指向同一引用,防止一次性标记被重置。Changes / 改动详情
File:
packages/nextra/src/server/index.tsAdded print-once helper (lines 26-35):
Changed line 115:
logger.info(...)→logI18nOnce(...)Testing / 测试步骤
English:
Enable i18n in
examples/docs/next.config.mjs:Start dev server:
Verify:
中文:
examples/docs/next.config.mjs中启用 i18nChecklist / 检查清单
Screenshots / 截图
Note: Screenshots would be helpful to show before/after terminal output. Since I cannot provide live screenshots, maintainers can test locally to verify.
注:建议添加修复前后的终端输出截图。维护者可以本地测试验证。
Related Issues / 相关问题
Closes #4763