fix: allow importing the bundle without a DOM - #210
Conversation
The webpack build picked the browser build of react-textarea-autosize, which reads document at import time. Bundle its default build instead, which checks for document first. Fixes microlinkhq#149 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@theluckystrike is attempting to deploy a commit to the Microlink Team on Vercel. A member of the Team first needs to authorize it. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughWebpack now resolves ChangesSSR bundle import
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change lets the bundle be imported without a DOM by using the default build of react-textarea-autosize. No actionable merge-blocking risk remains. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is narrowly scoped to server-compatible bundle loading. No new privileged capability or boundary bypass was identified. Verification remains limited because the exact dependency entry and generated bundle were unavailable. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Awesome, thanks! |
Fixes #149
What
require('@microlink/react-json-view')throwsReferenceError: document is not definedin Node. So the package breaks during SSR, for example in Next.js.Why
dist/main.jsis built with webpack for the web target. Forreact-textarea-autosize, webpack picks its browser build. That build runs this line when the module loads:The package also ships a default build that checks
typeof document !== 'undefined'first. That one works in both Node and the browser.How
One alias in
webpack/webpack.config.jspointsreact-textarea-autosizeat its default build. Nothing insrcchanges. In the browser it behaves the same. The minified bundle grows from 110501 to 112002 bytes.Tests
New test
test/tests/js/Bundle-test.jsbuilds the bundle with the real webpack config. Then it runs it in a freshvmcontext with nowindowordocument.Before the fix:
After the fix the full suite passes, 204 tests. I also checked the built
dist/main.jsby hand on Node 25:require('./dist/main.js')worksrenderToStringof<ReactJsonView src={{ a: 1 }} />returns HTMLimport('./index.mjs')worksstandardreports no new findings on the changed files.Summary by CodeRabbit