rampkit-expo-dev 0.0.26 → 0.0.27

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.
@@ -452,11 +452,38 @@ function Overlay(props) {
452
452
  .replace(/`/g, "\\`");
453
453
  return `(function(){try{document.dispatchEvent(new MessageEvent('message',{data:${json}}));}catch(e){}})();`;
454
454
  }
455
+ // Build a script that directly sets variables and triggers updates
456
+ // This is more reliable than dispatching events which may not be caught
457
+ function buildDirectVarsScript(vars) {
458
+ const json = JSON.stringify(vars)
459
+ .replace(/\\/g, "\\\\")
460
+ .replace(/`/g, "\\`");
461
+ return `(function(){
462
+ try {
463
+ var newVars = ${json};
464
+ // Directly update the global variables object
465
+ window.__rampkitVariables = newVars;
466
+ // Call the handler if available
467
+ if (typeof window.__rkHandleVarsUpdate === 'function') {
468
+ window.__rkHandleVarsUpdate(newVars);
469
+ }
470
+ // Dispatch custom event for any listeners
471
+ try {
472
+ document.dispatchEvent(new CustomEvent('rampkit:vars-updated', {detail: newVars}));
473
+ } catch(e) {}
474
+ // Call global callback if defined
475
+ if (typeof window.onRampkitVarsUpdate === 'function') {
476
+ window.onRampkitVarsUpdate(newVars);
477
+ }
478
+ } catch(e) {
479
+ console.log('[Rampkit] buildDirectVarsScript error:', e);
480
+ }
481
+ })();`;
482
+ }
455
483
  function sendVarsToWebView(i, isInitialLoad = false) {
456
484
  const wv = webviewsRef.current[i];
457
485
  if (!wv)
458
486
  return;
459
- const payload = { type: "rampkit:variables", vars: varsRef.current };
460
487
  if (__DEV__)
461
488
  console.log("[Rampkit] sendVarsToWebView", i, varsRef.current, { isInitialLoad });
462
489
  // Only update the stale filter timestamp during initial page load,
@@ -466,8 +493,10 @@ function Overlay(props) {
466
493
  if (isInitialLoad) {
467
494
  lastInitSendRef.current[i] = Date.now();
468
495
  }
496
+ // Use direct variable setting instead of MessageEvent dispatch
497
+ // This is more reliable as it doesn't depend on event listeners being set up
469
498
  // @ts-ignore: injectJavaScript exists on WebView instance
470
- wv.injectJavaScript(buildDispatchScript(payload));
499
+ wv.injectJavaScript(buildDirectVarsScript(varsRef.current));
471
500
  }
472
501
  function broadcastVars() {
473
502
  if (__DEV__)
@@ -475,14 +504,12 @@ function Overlay(props) {
475
504
  recipients: webviewsRef.current.length,
476
505
  vars: varsRef.current,
477
506
  });
507
+ const script = buildDirectVarsScript(varsRef.current);
478
508
  for (let i = 0; i < webviewsRef.current.length; i++) {
479
509
  const wv = webviewsRef.current[i];
480
510
  if (wv) {
481
511
  // @ts-ignore: injectJavaScript exists on WebView instance
482
- wv.injectJavaScript(buildDispatchScript({
483
- type: "rampkit:variables",
484
- vars: varsRef.current,
485
- }));
512
+ wv.injectJavaScript(script);
486
513
  }
487
514
  }
488
515
  }
@@ -655,28 +682,22 @@ function Overlay(props) {
655
682
  typeof data.vars === "object") {
656
683
  if (__DEV__)
657
684
  console.log("[Rampkit] received variables from page", i, data.vars);
658
- const now = Date.now();
659
- const lastInit = lastInitSendRef.current[i] || 0;
660
- const filtered = {};
685
+ // Accept all variable updates from pages without filtering.
686
+ // The previous filter was too aggressive and blocked legitimate
687
+ // user interactions that happened within 600ms of page load.
688
+ // We now trust that pages send correct variable updates.
661
689
  let changed = false;
690
+ const newVars = {};
662
691
  for (const [key, value] of Object.entries(data.vars)) {
663
692
  const hasHostVal = Object.prototype.hasOwnProperty.call(varsRef.current, key);
664
693
  const hostVal = varsRef.current[key];
665
- if (now - lastInit < 600 &&
666
- hasHostVal &&
667
- hostVal !== undefined &&
668
- value !== hostVal) {
669
- if (__DEV__)
670
- console.log("[Rampkit] ignore stale var from page", i, key, value, "kept", hostVal);
671
- continue;
672
- }
673
694
  if (!hasHostVal || hostVal !== value) {
674
- filtered[key] = value;
695
+ newVars[key] = value;
675
696
  changed = true;
676
697
  }
677
698
  }
678
699
  if (changed) {
679
- varsRef.current = { ...varsRef.current, ...filtered };
700
+ varsRef.current = { ...varsRef.current, ...newVars };
680
701
  broadcastVars();
681
702
  }
682
703
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rampkit-expo-dev",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "The Expo SDK for RampKit. Build, test, and personalize app onboardings with instant updates.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",