@liquidcommerce/elements-sdk 2.2.0-beta.4 → 2.2.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +1715 -569
  2. package/dist/index.esm.js +14589 -10538
  3. package/dist/types/constants/core.constant.d.ts +32 -0
  4. package/dist/types/constants/index.d.ts +0 -1
  5. package/dist/types/{modules/api-client → core}/api-client.service.d.ts +4 -2
  6. package/dist/types/core/auth.service.d.ts +31 -4
  7. package/dist/types/core/base-component.service.d.ts +7 -3
  8. package/dist/types/core/circuit-breaker.service.d.ts +54 -0
  9. package/dist/types/core/client/client-action.service.d.ts +19 -14
  10. package/dist/types/core/client/client-config.service.d.ts +5 -3
  11. package/dist/types/core/command/base-command.service.d.ts +5 -3
  12. package/dist/types/core/command/command.service.d.ts +2 -0
  13. package/dist/types/core/command/common-command.service.d.ts +2 -1
  14. package/dist/types/core/debug-panel/debug-panel.service.d.ts +43 -0
  15. package/dist/types/core/debug-panel/debug-panel.styles.d.ts +1 -0
  16. package/dist/types/core/fingerprint.service.d.ts +4 -9
  17. package/dist/types/core/google-tag-manager.service.d.ts +128 -2
  18. package/dist/types/core/logger/logger-factory.d.ts +3 -0
  19. package/dist/types/core/logger/logger.service.d.ts +8 -5
  20. package/dist/types/core/pubsub/interfaces/cart.interface.d.ts +1 -0
  21. package/dist/types/core/pubsub/interfaces/checkout.interface.d.ts +46 -6
  22. package/dist/types/core/pubsub/interfaces/core.interface.d.ts +5 -3
  23. package/dist/types/core/pubsub/interfaces/product.interface.d.ts +43 -6
  24. package/dist/types/core/pubsub/pubsub.service.d.ts +3 -2
  25. package/dist/types/core/sdk-error-handler.d.ts +1 -0
  26. package/dist/types/core/singleton-manager.service.d.ts +3 -3
  27. package/dist/types/core/store/interfaces/cart.interface.d.ts +1 -1
  28. package/dist/types/core/store/interfaces/checkout.interface.d.ts +0 -1
  29. package/dist/types/core/store/interfaces/core.interface.d.ts +5 -3
  30. package/dist/types/core/store/interfaces/product.interface.d.ts +18 -7
  31. package/dist/types/core/store/store.constant.d.ts +5 -1
  32. package/dist/types/core/store/store.service.d.ts +4 -2
  33. package/dist/types/core/telemetry/telemetry.interface.d.ts +80 -0
  34. package/dist/types/core/telemetry/telemetry.service.d.ts +27 -0
  35. package/dist/types/core/utils.d.ts +0 -4
  36. package/dist/types/elements-base-client.d.ts +49 -0
  37. package/dist/types/elements-builder-client.d.ts +2 -0
  38. package/dist/types/elements-client-helper.d.ts +3 -0
  39. package/dist/types/enums/core.enum.d.ts +9 -1
  40. package/dist/types/index.d.ts +1 -0
  41. package/dist/types/index.umd.d.ts +2 -2
  42. package/dist/types/interfaces/cloud/catalog.interface.d.ts +43 -0
  43. package/dist/types/interfaces/cloud/index.d.ts +1 -0
  44. package/dist/types/interfaces/cloud/product.interface.d.ts +2 -0
  45. package/dist/types/interfaces/configs/checkout.interface.d.ts +1 -1
  46. package/dist/types/interfaces/configs/product.interface.d.ts +2 -0
  47. package/dist/types/interfaces/core.interface.d.ts +47 -19
  48. package/dist/types/modules/address/address.command.d.ts +1 -3
  49. package/dist/types/modules/cart/cart.commands.d.ts +2 -3
  50. package/dist/types/modules/cart/cart.commands.helper.d.ts +3 -2
  51. package/dist/types/modules/cart/cart.component.d.ts +1 -2
  52. package/dist/types/modules/cart/components/cart-footer.component.d.ts +1 -0
  53. package/dist/types/modules/cart/components/cart-item.component.d.ts +2 -6
  54. package/dist/types/modules/cart/components/index.d.ts +2 -0
  55. package/dist/types/modules/checkout/checkout.commands.d.ts +4 -4
  56. package/dist/types/modules/checkout/checkout.commands.helper.d.ts +1 -1
  57. package/dist/types/modules/checkout/checkout.component.d.ts +1 -2
  58. package/dist/types/modules/checkout/components/checkout-summary-section.component.d.ts +2 -0
  59. package/dist/types/modules/checkout/components/information/checkout-delivery-information-form.component.d.ts +1 -1
  60. package/dist/types/modules/checkout/components/summary/checkout-item-quantity.component.d.ts +0 -2
  61. package/dist/types/modules/checkout/components/summary/checkout-item.component.d.ts +2 -1
  62. package/dist/types/modules/checkout/components/summary/checkout-items.component.d.ts +1 -0
  63. package/dist/types/modules/checkout/components/summary/checkout-place-order-button.component.d.ts +0 -1
  64. package/dist/types/modules/checkout/constant.d.ts +0 -1
  65. package/dist/types/modules/product/components/components.d.ts +1 -1
  66. package/dist/types/modules/product/components/index.d.ts +1 -0
  67. package/dist/types/modules/product/components/product-add-to-cart-section.component.d.ts +1 -0
  68. package/dist/types/modules/product/components/product-interactions.component.d.ts +4 -1
  69. package/dist/types/modules/product/components/product-price.component.d.ts +1 -0
  70. package/dist/types/modules/product/components/product-retailers.component.d.ts +1 -0
  71. package/dist/types/modules/product/product.commands.d.ts +3 -4
  72. package/dist/types/modules/product/utils/helpers.d.ts +1 -1
  73. package/dist/types/modules/product/utils/retailer-hours.d.ts +1 -1
  74. package/dist/types/modules/product-list/components/index.d.ts +2 -0
  75. package/dist/types/modules/product-list/components/product-list-card.component.d.ts +36 -0
  76. package/dist/types/modules/product-list/components/product-list-filters.component.d.ts +21 -0
  77. package/dist/types/modules/product-list/product-list.commands.d.ts +12 -0
  78. package/dist/types/modules/product-list/product-list.component.d.ts +76 -0
  79. package/dist/types/modules/theme-provider/constants/component-groupings.d.ts +0 -2
  80. package/dist/types/modules/theme-provider/services/font-manager.service.d.ts +1 -0
  81. package/dist/types/modules/theme-provider/styles/product-list/index.d.ts +1 -0
  82. package/dist/types/modules/theme-provider/styles/product-list/product-list.style.d.ts +1 -0
  83. package/dist/types/modules/ui-components/alert/alert.component.d.ts +1 -1
  84. package/dist/types/modules/ui-components/engraving/engraving-form.component.d.ts +13 -11
  85. package/dist/types/modules/ui-components/engraving/engraving-view.component.d.ts +4 -9
  86. package/dist/types/modules/ui-components/lce-element/lce-element.component.d.ts +2 -0
  87. package/dist/types/modules/ui-components/purchase-min-alert/helpers.d.ts +1 -1
  88. package/dist/types/modules/ui-components/ui.commands.d.ts +1 -1
  89. package/dist/types/static/icon/index.d.ts +0 -1
  90. package/dist/types/utils/format.d.ts +2 -1
  91. package/docs/ACTIONS.md +1300 -0
  92. package/docs/BROWSER_SUPPORT.md +279 -0
  93. package/docs/CONFIGURATION.md +740 -0
  94. package/docs/DOCUMENTATION_INDEX.md +311 -0
  95. package/docs/EVENTS.md +765 -0
  96. package/docs/PROXY.md +228 -0
  97. package/docs/THEMING.md +592 -0
  98. package/docs/TROUBLESHOOTING.md +793 -0
  99. package/package.json +20 -17
  100. package/umd/elements.js +1 -1
  101. package/dist/types/constants/z-index.constant.d.ts +0 -24
  102. package/dist/types/core/pubsub/index.d.ts +0 -2
  103. package/dist/types/core/pubsub/interfaces/index.d.ts +0 -5
  104. package/dist/types/core/store/index.d.ts +0 -2
  105. package/dist/types/core/store/interfaces/index.d.ts +0 -5
  106. package/dist/types/modules/address/index.d.ts +0 -4
  107. package/dist/types/modules/api-client/api-client.interface.d.ts +0 -21
  108. package/dist/types/modules/api-client/index.d.ts +0 -2
  109. package/dist/types/modules/cart/index.d.ts +0 -1
  110. package/dist/types/modules/checkout/index.d.ts +0 -1
  111. package/dist/types/modules/product/constant.d.ts +0 -2
  112. package/dist/types/modules/product/index.d.ts +0 -1
  113. package/dist/types/modules/theme-provider/index.d.ts +0 -2
  114. package/dist/types/static/icon/completed.icon.d.ts +0 -2
@@ -0,0 +1,793 @@
1
+ # Troubleshooting Guide
2
+
3
+ Common issues and solutions for the LiquidCommerce Elements SDK.
4
+
5
+ ## Address Management Issues
6
+
7
+ ### Address Clear Behavior
8
+
9
+ **Question:** What happens when I call `actions.address.clear()`?
10
+
11
+ **Answer:** The `actions.address.clear()` action performs a comprehensive reset:
12
+
13
+ - ✅ **Address Data**: Removes all saved address information
14
+ - ✅ **Cart Contents**: Completely resets the cart (removes all items, totals, promo codes)
15
+ - ✅ **Local Storage**: Completely removes the localStorage entry and its value
16
+ - ✅ **Database**: Deletes the persisted store from the server database
17
+ - ✅ **Checkout State**: Resets any pending checkout information
18
+
19
+ **Why does it reset the cart?**
20
+ Cart items have location-specific pricing, availability, and fulfillment options. Without a valid address, cart operations would fail or show incorrect data. The reset ensures data integrity.
21
+
22
+ **Events fired:**
23
+ - `lce:actions.address_cleared` - Address successfully cleared
24
+ - `lce:actions.cart_reset` - Cart successfully reset
25
+
26
+ ## SDK Initialization Issues
27
+
28
+ ### SDK Not Loading
29
+
30
+ **Symptom:** `Elements is not defined` or SDK not initializing
31
+
32
+ **Causes & Solutions:**
33
+
34
+ #### 1. Script Not Loaded
35
+
36
+ ```html
37
+ <!-- ❌ Wrong -->
38
+ <script src="https://assets-elements.liquidcommerce.us/all/elements.js" async></script>
39
+
40
+ <!-- ✅ Correct - Remove async or use onload -->
41
+ <script src="https://assets-elements.liquidcommerce.us/all/elements.js"></script>
42
+
43
+ <!-- Or with async -->
44
+ <script src="https://assets-elements.liquidcommerce.us/all/elements.js" async onload="initSDK()"></script>
45
+ ```
46
+
47
+ #### 2. Content Security Policy (CSP)
48
+
49
+ ```html
50
+ <!-- Add to your CSP -->
51
+ <meta http-equiv="Content-Security-Policy"
52
+ content="script-src 'self' https://assets-elements.liquidcommerce.us;">
53
+ ```
54
+
55
+ #### 3. Ad Blockers
56
+
57
+ **Solution:** Configure a [proxy](./PROXY.md) to route requests through your domain.
58
+
59
+ ### Authentication Failures
60
+
61
+ **Symptom:** `401 Unauthorized` or `Invalid API key`
62
+
63
+ **Solutions:**
64
+
65
+ ```javascript
66
+ // ✅ Check API key is correct
67
+ const client = await Elements('YOUR_ACTUAL_API_KEY', {
68
+ env: 'production' // Make sure env matches your key
69
+ });
70
+
71
+ // ✅ Verify environment
72
+ // Production keys won't work in development env
73
+ const client = await Elements('PROD_KEY', {
74
+ env: 'production' // Not 'development'
75
+ });
76
+ ```
77
+
78
+ **Check:**
79
+ - API key is correct
80
+ - Environment matches key (prod key → prod env)
81
+ - Key hasn't been revoked
82
+ - Domain is whitelisted in LiquidCommerce dashboard
83
+
84
+ ### Configuration Errors
85
+
86
+ **Symptom:** `Invalid configuration` errors
87
+
88
+ **Common mistakes:**
89
+
90
+ ```javascript
91
+ // ❌ Wrong - Invalid env value
92
+ { env: 'prod' } // Should be 'production'
93
+
94
+ // ❌ Wrong - Invalid debugMode
95
+ { debugMode: 'debug' } // Should be 'console' or 'panel'
96
+
97
+ // ❌ Wrong - Invalid proxy config
98
+ { proxy: 'https://...' } // Should be object with baseUrl
99
+
100
+ // ✅ Correct
101
+ {
102
+ env: 'production',
103
+ debugMode: 'none',
104
+ proxy: {
105
+ baseUrl: 'https://...'
106
+ }
107
+ }
108
+ ```
109
+
110
+ ## Component Rendering Issues
111
+
112
+ ### Components Not Appearing
113
+
114
+ **Symptom:** Container div is empty
115
+
116
+ **Debugging steps:**
117
+
118
+ ```javascript
119
+ // 1. Check container exists
120
+ const container = document.getElementById('product-container');
121
+ console.log('Container:', container); // Should not be null
122
+
123
+ // 2. Wait for DOM
124
+ window.addEventListener('DOMContentLoaded', async () => {
125
+ const client = await Elements('YOUR_API_KEY', { env: 'production' });
126
+ const components = await client.injectProductElement([
127
+ { containerId: 'product-container', identifier: 'product-123' }
128
+ ]);
129
+
130
+ // Check if injection was successful
131
+ if (components.length > 0) {
132
+ console.log('Product component injected successfully');
133
+ // components[0].rerender() - Rerender if needed
134
+ // components[0].getElement() - Get container element
135
+ // components[0].getType() - Get component type
136
+ } else {
137
+ console.log('Product injection failed');
138
+ }
139
+
140
+ // Debug: Check all injected components
141
+ const allComponents = client.getInjectedComponents();
142
+ console.log('All injected components:', allComponents);
143
+ allComponents.forEach((component, containerId) => {
144
+ console.log(`Container: ${containerId}, Type: ${component.getType()}`);
145
+ });
146
+ });
147
+
148
+ // 3. Monitor product loading
149
+ window.addEventListener('lce:actions.product_loaded', (event) => {
150
+ console.log('Product loaded:', event.detail.data);
151
+ });
152
+ ```
153
+
154
+ **Common issues:**
155
+ - Container doesn't exist when SDK tries to inject
156
+ - Product identifier is invalid
157
+ - Product not available in current environment
158
+
159
+ ### Styling Issues
160
+
161
+ **Symptom:** Components look broken or unstyled
162
+
163
+ **Solutions:**
164
+
165
+ ```javascript
166
+ // 1. Check for CSS conflicts
167
+ // Look for these in your CSS:
168
+ // - * { all: unset }
169
+ // - Overly broad selectors affecting [data-lce-*]
170
+
171
+ // 2. Verify theme config
172
+ const client = await Elements('YOUR_API_KEY', {
173
+ customTheme: {
174
+ global: {
175
+ colors: {
176
+ primary: '#007bff' // Valid hex color
177
+ }
178
+ }
179
+ }
180
+ });
181
+
182
+ // 3. Check z-index conflicts
183
+ // SDK uses z-index 1000-1070 for modals/drawers
184
+ ```
185
+
186
+ ### Layout Issues
187
+
188
+ **Symptom:** Components overlapping or misaligned
189
+
190
+ **Solutions:**
191
+
192
+ ```css
193
+ /* Ensure container has proper display */
194
+ #product-container {
195
+ display: block;
196
+ width: 100%;
197
+ min-height: 400px; /* Prevent collapsing */
198
+ }
199
+
200
+ /* Fix flexbox/grid conflicts */
201
+ #product-container > * {
202
+ flex: initial;
203
+ grid-column: initial;
204
+ }
205
+ ```
206
+
207
+ ## Event Handling Issues
208
+
209
+ ### Events Not Firing
210
+
211
+ **Symptom:** Event listeners not being called
212
+
213
+ **Solutions:**
214
+
215
+ ```javascript
216
+ // ✅ Correct - Set up listener BEFORE action
217
+ window.addEventListener('lce:actions.cart_updated', handleUpdate);
218
+ await client.actions.cart.addProduct([...]);
219
+
220
+ // ❌ Wrong - Listener after action (might miss event)
221
+ await client.actions.cart.addProduct([...]);
222
+ window.addEventListener('lce:actions.cart_updated', handleUpdate);
223
+
224
+ // ✅ Use capture phase for guaranteed delivery
225
+ window.addEventListener('lce:actions.cart_updated', handleUpdate, true);
226
+ ```
227
+
228
+ ### Event Data Missing
229
+
230
+ **Symptom:** `event.detail.data` is undefined
231
+
232
+ **Check:**
233
+
234
+ ```javascript
235
+ window.addEventListener('lce:actions.cart_updated', (event) => {
236
+ // ❌ Wrong
237
+ const data = event.data;
238
+
239
+ // ✅ Correct
240
+ const data = event.detail.data;
241
+
242
+ console.log('Cart data:', data);
243
+ });
244
+ ```
245
+
246
+ ### Multiple Event Firings
247
+
248
+ **Symptom:** Event listener called multiple times unexpectedly
249
+
250
+ **Solution:**
251
+
252
+ ```javascript
253
+ // ❌ Problem - Adding listener multiple times
254
+ function setupListeners() {
255
+ window.addEventListener('lce:actions.cart_updated', handleUpdate);
256
+ }
257
+
258
+ // ✅ Solution - Remove before adding
259
+ function setupListeners() {
260
+ window.removeEventListener('lce:actions.cart_updated', handleUpdate);
261
+ window.addEventListener('lce:actions.cart_updated', handleUpdate);
262
+ }
263
+
264
+ // Or use once option
265
+ window.addEventListener('lce:actions.cart_updated', handleUpdate, { once: true });
266
+ ```
267
+
268
+ ## Cart & Checkout Issues
269
+
270
+ ### Cart Not Persisting
271
+
272
+ **Symptom:** Cart clears on page reload
273
+
274
+ **Causes:**
275
+
276
+ ```javascript
277
+ // 1. LocalStorage disabled
278
+ if (!('localStorage' in window)) {
279
+ console.error('LocalStorage not available');
280
+ }
281
+
282
+ // 2. Private/Incognito mode
283
+ // LocalStorage is disabled in private browsing
284
+
285
+ // 3. Storage quota exceeded
286
+ try {
287
+ localStorage.setItem('test', 'test');
288
+ } catch (e) {
289
+ console.error('Storage error:', e);
290
+ }
291
+ ```
292
+
293
+ **Solutions:**
294
+ - Ask users to enable cookies/storage
295
+ - Warn users about private mode limitations
296
+ - Clear old localStorage data
297
+
298
+ ### Checkout Failing
299
+
300
+ **Symptom:** Checkout submit errors
301
+
302
+ **Common causes:**
303
+
304
+ ```javascript
305
+ // Listen for specific errors
306
+ window.addEventListener('lce:actions.checkout_submit_failed', (event) => {
307
+ const { error, reason } = event.detail.data;
308
+
309
+ if (reason.includes('payment')) {
310
+ // Payment declined
311
+ showPaymentError();
312
+ } else if (reason.includes('inventory')) {
313
+ // Out of stock
314
+ showInventoryError();
315
+ } else if (reason.includes('address')) {
316
+ // Invalid address
317
+ showAddressError();
318
+ }
319
+ });
320
+ ```
321
+
322
+ **Debug steps:**
323
+ 1. Check address is set: `client.actions.address.getDetails()`
324
+ 2. Check cart has items: `client.actions.cart.getDetails()`
325
+ 3. Verify payment info is complete
326
+ 4. Check for form validation errors
327
+ 5. Look for network errors in console
328
+
329
+ ### Promo Code Issues
330
+
331
+ **Symptom:** Promo codes not applying
332
+
333
+ **Debug:**
334
+
335
+ ```javascript
336
+ // Listen for promo failures
337
+ window.addEventListener('lce:actions.cart_promo_code_failed', (event) => {
338
+ const { error } = event.detail.data;
339
+ console.error('Promo failed:', error);
340
+
341
+ // Common errors:
342
+ // - "Promo code expired"
343
+ // - "Cart minimum not met"
344
+ // - "Promo code invalid"
345
+ // - "Promo already applied"
346
+ });
347
+
348
+ // Verify promo is active
349
+ // Check LiquidCommerce dashboard for promo settings
350
+ ```
351
+
352
+ ## Address Validation Issues
353
+
354
+ ### Google Places Not Working
355
+
356
+ **Symptom:** Address autocomplete not appearing
357
+
358
+ **Causes:**
359
+
360
+ ```javascript
361
+ // 1. Google Places API key missing/invalid
362
+ // Check browser console for Google API errors
363
+
364
+ // 2. Domain not authorized
365
+ // Add your domain to Google Cloud Console
366
+
367
+ // 3. API not enabled
368
+ // Enable Places API in Google Cloud Console
369
+ ```
370
+
371
+ ### Manual Address Issues
372
+
373
+ **Symptom:** Manual address not working
374
+
375
+ **Solutions:**
376
+
377
+ ```javascript
378
+ // Ensure coordinates are valid
379
+ const isValidLat = lat >= -90 && lat <= 90;
380
+ const isValidLng = lng >= -180 && lng <= 180;
381
+
382
+ if (!isValidLat || !isValidLng) {
383
+ console.error('Invalid coordinates');
384
+ }
385
+
386
+ // Use proper format
387
+ await client.actions.address.setAddressManually(
388
+ {
389
+ one: '123 Main St',
390
+ two: 'Apt 4B', // Optional but must be string
391
+ city: 'New York',
392
+ state: 'NY',
393
+ zip: '10001',
394
+ country: 'United States'
395
+ },
396
+ {
397
+ lat: 40.7505045,
398
+ long: -73.9934387 // Note: "long" not "lng"
399
+ }
400
+ );
401
+ ```
402
+
403
+ ## Network & API Issues
404
+
405
+ ### CORS Errors
406
+
407
+ **Symptom:** `Access-Control-Allow-Origin` errors
408
+
409
+ **Solutions:**
410
+
411
+ ```javascript
412
+ // 1. Use proxy to avoid CORS
413
+ const client = await Elements('YOUR_API_KEY', {
414
+ proxy: {
415
+ baseUrl: 'https://yourdomain.com/api/liquidcommerce'
416
+ }
417
+ });
418
+
419
+ // 2. Check domain whitelist
420
+ // Verify your domain is whitelisted in LiquidCommerce dashboard
421
+
422
+ // 3. Development workaround
423
+ // Use browser extension to disable CORS (dev only!)
424
+ ```
425
+
426
+ ### Slow API Responses
427
+
428
+ **Symptom:** Components take long to load
429
+
430
+ **Debug:**
431
+
432
+ ```javascript
433
+ // 1. Enable debug mode
434
+ const client = await Elements('YOUR_API_KEY', {
435
+ debugMode: 'console'
436
+ });
437
+
438
+ // 2. Check network tab
439
+ // Look for slow API calls
440
+
441
+ // 3. Monitor for failures
442
+ window.addEventListener('lce:actions.cart_failed', (event) => {
443
+ console.warn('Cart operation failed:', event.detail);
444
+ });
445
+ ```
446
+
447
+ **Solutions:**
448
+ - Configure proxy for better routing
449
+ - Check internet connection
450
+ - Verify API status (LiquidCommerce status page)
451
+ - Use CDN for SDK script (automatic caching)
452
+
453
+ ### API Rate Limiting
454
+
455
+ **Symptom:** `429 Too Many Requests`
456
+
457
+ **Solutions:**
458
+
459
+ ```javascript
460
+ // Implement retry logic
461
+ async function addToCartWithRetry(params, maxRetries = 3) {
462
+ for (let i = 0; i < maxRetries; i++) {
463
+ try {
464
+ await client.actions.cart.addProduct(params);
465
+ return;
466
+ } catch (error) {
467
+ if (error.status === 429) {
468
+ // Wait before retry
469
+ await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
470
+ } else {
471
+ throw error;
472
+ }
473
+ }
474
+ }
475
+ }
476
+ ```
477
+
478
+ ## Performance Issues
479
+
480
+ ### Slow Page Load
481
+
482
+ **Symptom:** SDK slows down page load
483
+
484
+ **Solutions:**
485
+
486
+ ```html
487
+ <!-- 1. Use defer attribute -->
488
+ <script defer src="https://assets-elements.liquidcommerce.us/all/elements.js"></script>
489
+
490
+ <!-- 2. Load at end of body -->
491
+ <body>
492
+ <!-- Page content -->
493
+ <script src="https://assets-elements.liquidcommerce.us/all/elements.js"></script>
494
+ </body>
495
+
496
+ <!-- 3. Lazy load components -->
497
+ <script>
498
+ window.addEventListener('load', async () => {
499
+ const client = await Elements('YOUR_API_KEY', { env: 'production' });
500
+ // Initialize after page load
501
+ });
502
+ </script>
503
+ ```
504
+
505
+ ### Memory Leaks
506
+
507
+ **Symptom:** Page becomes slow over time
508
+
509
+ **Solutions:**
510
+
511
+ ```javascript
512
+ // Remove event listeners when done
513
+ function cleanup() {
514
+ window.removeEventListener('lce:actions.cart_updated', handleUpdate);
515
+ window.removeEventListener('lce:actions.product_loaded', handleProduct);
516
+ }
517
+
518
+ // In React/Vue
519
+ useEffect(() => {
520
+ window.addEventListener('lce:actions.cart_updated', handleUpdate);
521
+
522
+ return () => {
523
+ window.removeEventListener('lce:actions.cart_updated', handleUpdate);
524
+ };
525
+ }, []);
526
+ ```
527
+
528
+ ### High CPU Usage
529
+
530
+ **Symptom:** Browser tab using excessive CPU
531
+
532
+ **Check:**
533
+
534
+ ```javascript
535
+ // 1. Disable debug mode in production
536
+ {
537
+ debugMode: 'none' // Not 'panel'
538
+ }
539
+
540
+ // 2. Minimize theme complexity
541
+ {
542
+ customTheme: {
543
+ global: {
544
+ colors: {
545
+ primary: '#007bff' // Only override what's needed
546
+ }
547
+ }
548
+ }
549
+ }
550
+
551
+ // 3. Reduce event listeners
552
+ // Use event delegation instead of many listeners
553
+ ```
554
+
555
+ ## Mobile-Specific Issues
556
+
557
+ ### Touch Events Not Working
558
+
559
+ **Symptom:** Buttons/interactions not responding on mobile
560
+
561
+ **Check:**
562
+
563
+ ```css
564
+ /* Ensure touch targets are large enough */
565
+ button {
566
+ min-height: 44px; /* iOS minimum */
567
+ min-width: 44px;
568
+ }
569
+
570
+ /* Fix iOS double-tap zoom */
571
+ button {
572
+ touch-action: manipulation;
573
+ }
574
+ ```
575
+
576
+ ### Viewport Issues
577
+
578
+ **Symptom:** Components too small or zoomed on mobile
579
+
580
+ **Solution:**
581
+
582
+ ```html
583
+ <!-- Ensure viewport meta tag is present -->
584
+ <meta name="viewport" content="width=device-width, initial-scale=1">
585
+ ```
586
+
587
+ ### Keyboard Covering Input
588
+
589
+ **Symptom:** Keyboard covers form fields on mobile
590
+
591
+ **Solution:**
592
+
593
+ ```javascript
594
+ // SDK handles this automatically, but if issues persist:
595
+ document.addEventListener('focusin', (e) => {
596
+ if (e.target.tagName === 'INPUT') {
597
+ setTimeout(() => {
598
+ e.target.scrollIntoView({ behavior: 'smooth', block: 'center' });
599
+ }, 300);
600
+ }
601
+ });
602
+ ```
603
+
604
+ ## Framework-Specific Issues
605
+
606
+ ### React Issues
607
+
608
+ **Problem:** SDK initializes multiple times
609
+
610
+ **Solution:**
611
+
612
+ ```jsx
613
+ import { useEffect, useRef } from 'react';
614
+
615
+ function App() {
616
+ const clientRef = useRef(null);
617
+
618
+ useEffect(() => {
619
+ async function init() {
620
+ if (!clientRef.current) {
621
+ clientRef.current = await Elements('YOUR_API_KEY', { env: 'production' });
622
+ }
623
+ }
624
+ init();
625
+ }, []); // Empty deps - initialize once
626
+
627
+ return <div id="product-container"></div>;
628
+ }
629
+ ```
630
+
631
+ ### Next.js Issues
632
+
633
+ **Problem:** `window is not defined` (SSR)
634
+
635
+ **Solution:**
636
+
637
+ ```javascript
638
+ // pages/product.js
639
+ import { useEffect } from 'react';
640
+
641
+ export default function Product() {
642
+ useEffect(() => {
643
+ // Only run on client
644
+ async function init() {
645
+ if (typeof window !== 'undefined') {
646
+ const { Elements } = await import('@liquidcommerce/elements-sdk');
647
+ const client = await Elements(process.env.NEXT_PUBLIC_LCE_API_KEY, {
648
+ env: 'production'
649
+ });
650
+ }
651
+ }
652
+ init();
653
+ }, []);
654
+
655
+ return <div id="product-container"></div>;
656
+ }
657
+ ```
658
+
659
+ ### Vue Issues
660
+
661
+ **Problem:** Components not reactive
662
+
663
+ **Solution:**
664
+
665
+ ```vue
666
+ <script setup>
667
+ import { onMounted, ref } from 'vue';
668
+
669
+ const cartData = ref(null);
670
+
671
+ onMounted(async () => {
672
+ const client = await Elements(import.meta.env.VITE_LCE_API_KEY, {
673
+ env: 'production'
674
+ });
675
+
676
+ window.addEventListener('lce:actions.cart_updated', (event) => {
677
+ cartData.value = event.detail.data.current; // Vue reactivity
678
+ });
679
+ });
680
+ </script>
681
+ ```
682
+
683
+ ## Browser-Specific Issues
684
+
685
+ ### Safari Issues
686
+
687
+ **Problem:** LocalStorage quota exceeded
688
+
689
+ **Solution:**
690
+
691
+ ```javascript
692
+ try {
693
+ localStorage.setItem('lce_cart', JSON.stringify(cart));
694
+ } catch (e) {
695
+ if (e.name === 'QuotaExceededError') {
696
+ // Clear old data
697
+ localStorage.removeItem('lce_old_cart');
698
+ // Retry
699
+ localStorage.setItem('lce_cart', JSON.stringify(cart));
700
+ }
701
+ }
702
+ ```
703
+
704
+ ### Firefox Issues
705
+
706
+ **Problem:** Different rendering/layout
707
+
708
+ **Solution:**
709
+
710
+ ```css
711
+ /* Add Firefox-specific fixes if needed */
712
+ @-moz-document url-prefix() {
713
+ .lce-component {
714
+ /* Firefox-specific styles */
715
+ }
716
+ }
717
+ ```
718
+
719
+ ## Debugging Tools
720
+
721
+ ### Enable Debug Mode
722
+
723
+ ```javascript
724
+ const client = await Elements('YOUR_API_KEY', {
725
+ debugMode: 'panel' // Shows visual debug panel
726
+ });
727
+ ```
728
+
729
+ ### Check SDK State
730
+
731
+ ```javascript
732
+ // Get current state
733
+ const cart = await client.actions.cart.getDetails();
734
+ const address = await client.actions.address.getDetails();
735
+ const checkout = await client.actions.checkout.getDetails();
736
+
737
+ console.log('Cart:', cart);
738
+ console.log('Address:', address);
739
+ console.log('Checkout:', checkout);
740
+ ```
741
+
742
+ ### Monitor All Events
743
+
744
+ ```javascript
745
+ // Log all SDK events
746
+ window.elements.onAllActions((data, metadata) => {
747
+ console.log('Action:', metadata.eventName, data);
748
+ });
749
+
750
+ window.elements.onAllForms((data, metadata) => {
751
+ console.log('Form:', metadata.eventName, data);
752
+ });
753
+ ```
754
+
755
+ ### Network Inspection
756
+
757
+ ```javascript
758
+ // Monitor cart operations
759
+ window.addEventListener('lce:actions.cart_loaded', (event) => {
760
+ console.log('Cart loaded:', event.detail.data);
761
+ });
762
+
763
+ window.addEventListener('lce:actions.cart_failed', (event) => {
764
+ console.error('Cart operation failed:', event.detail.data);
765
+ });
766
+ ```
767
+
768
+ ## Getting Help
769
+
770
+ If you're still experiencing issues:
771
+
772
+ 1. **Check the console** for error messages
773
+ 2. **Enable debug mode** to see detailed logs
774
+ 3. **Check network tab** for failed requests
775
+ 4. **Verify configuration** matches documentation
776
+ 5. **Test in incognito mode** to rule out extensions
777
+ 6. **Try a different browser** to isolate browser-specific issues
778
+ 7. **Check LiquidCommerce status page** for API issues
779
+ 8. **Contact support** with:
780
+ - SDK version
781
+ - Browser and OS
782
+ - Console errors
783
+ - Steps to reproduce
784
+ - Minimal code example
785
+
786
+ ## Related Documentation
787
+
788
+ - [Configuration Reference](./CONFIGURATION.md) - Configuration options
789
+ - [Actions Reference](./ACTIONS.md) - Programmatic control
790
+ - [Events Reference](./EVENTS.md) - Event system
791
+ - [Browser Support](./BROWSER_SUPPORT.md) - Browser compatibility
792
+ - [Proxy Setup](./PROXY.md) - Proxy configuration
793
+