@thewhateverapp/tile-sdk 0.8.4 → 0.8.6

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.
@@ -38,17 +38,20 @@ export declare class TileBridge {
38
38
  private handleConfig;
39
39
  private handleResponse;
40
40
  private handleEvent;
41
+ private handleParentNavigate;
41
42
  private sendToParent;
42
43
  /**
43
44
  * Request to navigate to full page view
44
45
  * SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
45
46
  * In preview mode, only sends event to parent (no route change)
47
+ * Includes fallback for when router.push fails (e.g., due to hydration errors)
46
48
  */
47
49
  navigateToPage(): void;
48
50
  /**
49
51
  * Request to navigate back to tile view (from page)
50
52
  * SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
51
53
  * In preview mode, only sends event to parent (no route change)
54
+ * Includes fallback for when router.push fails (e.g., due to hydration errors)
52
55
  */
53
56
  navigateToTile(): void;
54
57
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"TileBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/TileBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAGD,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,CAAC,IAAI,EAAE,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AAE,UAAU,GAAG,UAAU,CAQ7D"}
@@ -80,6 +80,9 @@ export class TileBridge {
80
80
  case 'parent:event':
81
81
  this.handleEvent(message);
82
82
  break;
83
+ case 'parent:navigate':
84
+ this.handleParentNavigate(message.payload);
85
+ break;
83
86
  default:
84
87
  // Handle custom messages
85
88
  this.emitEvent(message.type, message.payload);
@@ -110,6 +113,24 @@ export class TileBridge {
110
113
  handleEvent(message) {
111
114
  this.emitEvent(message.payload?.type, message.payload?.data);
112
115
  }
116
+ handleParentNavigate(payload) {
117
+ const target = payload?.target;
118
+ if (this.isDevelopment() || this.isPreview()) {
119
+ console.log('[TileBridge] 📥 Received parent:navigate', { target, hasRouter: !!this.router });
120
+ }
121
+ // Navigate using router if available
122
+ if (target === 'tile' || target === 'page') {
123
+ const path = `/${target}`;
124
+ if (this.router) {
125
+ console.log(`[TileBridge] ✅ Navigating to ${path} via router`);
126
+ this.router.push(path);
127
+ }
128
+ else if (typeof window !== 'undefined') {
129
+ console.log(`[TileBridge] ⚠️ No router, using window.location fallback to ${path}`);
130
+ window.location.pathname = path;
131
+ }
132
+ }
133
+ }
113
134
  sendToParent(message) {
114
135
  if (typeof window === 'undefined' || !window.parent)
115
136
  return;
@@ -144,14 +165,16 @@ export class TileBridge {
144
165
  * Request to navigate to full page view
145
166
  * SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
146
167
  * In preview mode, only sends event to parent (no route change)
168
+ * Includes fallback for when router.push fails (e.g., due to hydration errors)
147
169
  */
148
170
  navigateToPage() {
149
171
  const inPreview = this.isPreview();
172
+ const currentPath = typeof window !== 'undefined' ? window.location.pathname : 'unknown';
150
173
  console.log('[TileBridge] 🚀 navigateToPage() called', {
151
174
  hasRouter: !!this.router,
152
175
  isInIframe: this.isInIframe(),
153
176
  inPreview,
154
- currentPath: typeof window !== 'undefined' ? window.location.pathname : 'unknown',
177
+ currentPath,
155
178
  });
156
179
  // In preview mode, only notify parent - don't change routes in iframe
157
180
  if (inPreview) {
@@ -165,11 +188,29 @@ export class TileBridge {
165
188
  // 1. Navigate directly using Next.js router (deployed apps only)
166
189
  if (this.router) {
167
190
  console.log('[TileBridge] ✅ Using router.push("/page")');
168
- this.router.push('/page');
191
+ try {
192
+ this.router.push('/page');
193
+ // Fallback: Check if navigation actually happened after a short delay
194
+ // This handles cases where router is broken due to hydration errors
195
+ if (typeof window !== 'undefined') {
196
+ setTimeout(() => {
197
+ if (window.location.pathname !== '/page') {
198
+ console.log('[TileBridge] ⚠️ router.push failed, falling back to window.location');
199
+ window.location.href = '/page';
200
+ }
201
+ }, 100);
202
+ }
203
+ }
204
+ catch (err) {
205
+ console.error('[TileBridge] router.push error, falling back:', err);
206
+ if (typeof window !== 'undefined') {
207
+ window.location.href = '/page';
208
+ }
209
+ }
169
210
  }
170
211
  else if (typeof window !== 'undefined') {
171
212
  console.log('[TileBridge] ⚠️ No router, using window.location fallback');
172
- window.location.pathname = '/page';
213
+ window.location.href = '/page';
173
214
  }
174
215
  // 2. Notify parent to enter fullscreen mode
175
216
  console.log('[TileBridge] 📤 Sending tile:navigate message to parent');
@@ -182,6 +223,7 @@ export class TileBridge {
182
223
  * Request to navigate back to tile view (from page)
183
224
  * SIMPLE & EXPLICIT: Directly navigates using Next.js router + notifies parent
184
225
  * In preview mode, only sends event to parent (no route change)
226
+ * Includes fallback for when router.push fails (e.g., due to hydration errors)
185
227
  */
186
228
  navigateToTile() {
187
229
  const inPreview = this.isPreview();
@@ -203,10 +245,27 @@ export class TileBridge {
203
245
  }
204
246
  // 1. Navigate directly using Next.js router (deployed apps only)
205
247
  if (this.router) {
206
- this.router.push('/tile');
248
+ try {
249
+ this.router.push('/tile');
250
+ // Fallback: Check if navigation actually happened after a short delay
251
+ if (typeof window !== 'undefined') {
252
+ setTimeout(() => {
253
+ if (window.location.pathname !== '/tile') {
254
+ console.log('[TileBridge] ⚠️ router.push failed, falling back to window.location');
255
+ window.location.href = '/tile';
256
+ }
257
+ }, 100);
258
+ }
259
+ }
260
+ catch (err) {
261
+ console.error('[TileBridge] router.push error, falling back:', err);
262
+ if (typeof window !== 'undefined') {
263
+ window.location.href = '/tile';
264
+ }
265
+ }
207
266
  }
208
267
  else if (typeof window !== 'undefined') {
209
- window.location.pathname = '/tile';
268
+ window.location.href = '/tile';
210
269
  }
211
270
  // 2. Notify parent to exit fullscreen mode
212
271
  this.sendToParent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/tile-sdk",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "SDK for building interactive tiles on The Whatever App platform",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",