fix(checkout): guard billing_zip_code v-if against undefined uses_postal_code#1318
Conversation
…tal_code The billing_zip_code field's Vue v-if expression references uses_postal_code without a guard. When older or minified checkout bundles render before the Vue data key has been registered (timing-dependent on order of script loading / hydration), the expression throws a ReferenceError and the checkout form fails to render at all. Wrap the symbol with typeof X === 'undefined' so the form falls back to showing the ZIP field instead of crashing. Defaulting to visible is the safe choice — the field still validates and submits, and the symbol becomes defined on subsequent re-renders. Includes a regression test asserting the guard is present in the generated wrapper attribute so future refactors don't quietly drop it.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR adds a safety guard to prevent ChangesBilling Zip Code Visibility Guard
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
Summary
The
billing_zip_codecheckout field's Vuev-ifexpression referencesuses_postal_codewithout a guard. When older or minified checkout bundles render before the Vue data key has been registered, the expression throws aReferenceErrorand the entire checkout form fails to render.This change wraps the symbol with
typeof X === 'undefined'so the form falls back to showing the ZIP field instead of crashing.The bug
inc/checkout/signup-fields/class-signup-field-billing-address.php:355(before):If the Vue instance attempts to evaluate this expression before
uses_postal_codehas been registered as a data key, Vue throwsReferenceError: uses_postal_code is not definedand the surrounding<div v-if>collapses — taking the entire billing block with it on some renderings.The fix
Defaulting to visible when the symbol is undefined is the safe choice:
Country_Default) hide the field onceuses_postal_codeis defined and falsy, so the previous behaviour is preserved in steady state.The alternative — defaulting to hidden when undefined — would prevent users from filling in the ZIP at all on the first render, which is a worse failure mode than showing a field that may not strictly be required.
Test
Adds
test_zip_visibility_guards_uses_postal_code_symboltotests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Billing_Address_Test.php:This asserts the guard is present in the generated wrapper attribute so future refactors don't quietly drop it.
Verification
vendor/bin/phpcs --standard=.phpcs.xml.dist <both files>→ clean (0 errors, 0 warnings).vendor/bin/phpstan analyse <both files>→ clean (No errors).vendor/bin/phpunit --filter test_zip_visibility_guards_uses_postal_code_symbol …→OK (1 test, 3 assertions).Scope
Pure defensive guard against a JS runtime error. No behaviour change in steady state. No new dependencies, no schema change, no migration.
Files touched:
inc/checkout/signup-fields/class-signup-field-billing-address.php— 1 line changed (the v-if string), 3 lines added (docblock explanation).tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Billing_Address_Test.php— 1 new test method (19 lines including docblock and arrange/act/assert).Total: +23 / −1.
aidevops.sh v3.20.5 plugin for OpenCode v1.15.12 with claude-opus-4-7 spent 1d 13h and 655,199 tokens on this with the user in an interactive session.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests