Skip to content

Commit 0844b5b

Browse files
d-winterclaude
andauthored
Remove unused locale support from SDK (#5)
Locale/i18n support was scaffolded but never implemented - see Preview.ts:398 which explicitly passed `undefined // locale not supported yet`. Removed from: - Types (StudioMessage, SDKMessage, FieldUpdateBase, ElementAttributes, etc.) - Core modules (Preview, FieldRegistry, ContentUpdater, OverlayManager) - Attribute helpers (createPreviewAttributes, PreviewFieldOptions) - React components (HygraphPreview, HygraphPreviewNextjs) - Tests (removed locale-specific test, updated attribute test) No breaking changes - locale was never documented or functional. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 27114b2 commit 0844b5b

File tree

10 files changed

+26
-91
lines changed

10 files changed

+26
-91
lines changed

src/core/ContentUpdater.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,6 @@ describe('ContentUpdater', () => {
4444
expect(result.error).toBe('No matching elements found');
4545
});
4646

47-
it('respects locale when selecting elements', async () => {
48-
const element = createPreviewElement({
49-
entryId: 'entry-locale',
50-
fieldApiId: 'title',
51-
locale: 'en',
52-
textContent: 'Hello',
53-
});
54-
55-
createPreviewElement({
56-
entryId: 'entry-locale',
57-
fieldApiId: 'title',
58-
locale: 'de',
59-
textContent: 'Hallo',
60-
});
61-
62-
const result = await updater.updateField({
63-
entryId: 'entry-locale',
64-
fieldApiId: 'title',
65-
locale: 'en',
66-
fieldType: 'STRING',
67-
newValue: 'Updated EN',
68-
});
69-
70-
expect(result.success).toBe(true);
71-
expect(element.textContent).toBe('Updated EN');
72-
});
73-
7447
it('applies multi-format rich text updates based on element preference', async () => {
7548
const element = createPreviewElement({
7649
entryId: 'entry-rich-text',

src/core/ContentUpdater.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ContentUpdater {
3636

3737
try {
3838
// Debounce updates
39-
const updateKey = `${update.entryId}:${update.fieldApiId}:${update.locale || ''}`;
39+
const updateKey = `${update.entryId}:${update.fieldApiId}`;
4040
this.updateQueue.set(updateKey, update);
4141

4242
// Wait for debounce delay
@@ -52,7 +52,7 @@ export class ContentUpdater {
5252
this.updateQueue.delete(updateKey);
5353

5454
// Find target elements
55-
const elements = this.findElements(update.entryId, update.fieldApiId, update.locale);
55+
const elements = this.findElements(update.entryId, update.fieldApiId);
5656
if (elements.length === 0) {
5757
return { success: false, error: 'No matching elements found' };
5858
}
@@ -79,7 +79,6 @@ export class ContentUpdater {
7979
console.log('[ContentUpdater] Updated field:', {
8080
entryId: update.entryId,
8181
fieldApiId: update.fieldApiId,
82-
locale: update.locale,
8382
elementsCount: elements.length,
8483
});
8584
}
@@ -101,17 +100,14 @@ export class ContentUpdater {
101100
this.updateQueue.clear();
102101
}
103102

104-
private findElements(entryId: string, fieldApiId?: string, locale?: string): HTMLElement[] {
103+
private findElements(entryId: string, fieldApiId?: string): HTMLElement[] {
105104
const elements: HTMLElement[] = [];
106105

107106
// Build selector
108107
let selector = `[data-hygraph-entry-id="${entryId}"]`;
109108
if (fieldApiId) {
110109
selector += `[data-hygraph-field-api-id="${fieldApiId}"]`;
111110
}
112-
if (locale) {
113-
selector += `[data-hygraph-field-locale="${locale}"]`;
114-
}
115111

116112
const found = document.querySelectorAll<HTMLElement>(selector);
117113
elements.push(...Array.from(found));

src/core/FieldRegistry.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ export class FieldRegistry {
2525
/**
2626
* Get all elements for a specific field
2727
*/
28-
getElementsForField(fieldApiId: string, locale?: string): RegisteredElement[] {
28+
getElementsForField(fieldApiId: string): RegisteredElement[] {
2929
const elements: RegisteredElement[] = [];
3030

31-
// Search through all registry entries for matching fieldApiId and locale
31+
// Search through all registry entries for matching fieldApiId
3232
for (const elementList of Object.values(this.registry)) {
3333
for (const element of elementList) {
34-
if (element.fieldApiId === fieldApiId && element.locale === locale) {
34+
if (element.fieldApiId === fieldApiId) {
3535
elements.push(element);
3636
}
3737
}
@@ -43,15 +43,13 @@ export class FieldRegistry {
4343
/**
4444
* Get elements for a specific entry + field combination
4545
*/
46-
getElementsForEntryField(entryId: string, fieldApiId: string, locale?: string): RegisteredElement[] {
46+
getElementsForEntryField(entryId: string, fieldApiId: string): RegisteredElement[] {
4747
const elements: RegisteredElement[] = [];
4848

49-
// Search through all registry entries for matching entryId, fieldApiId, and locale
49+
// Search through all registry entries for matching entryId and fieldApiId
5050
for (const elementList of Object.values(this.registry)) {
5151
for (const element of elementList) {
52-
if (element.entryId === entryId &&
53-
element.fieldApiId === fieldApiId &&
54-
element.locale === locale) {
52+
if (element.entryId === entryId && element.fieldApiId === fieldApiId) {
5553
elements.push(element);
5654
}
5755
}
@@ -80,8 +78,8 @@ export class FieldRegistry {
8078
/**
8179
* Get specific element by exact match
8280
*/
83-
getElement(entryId: string, fieldApiId?: string, locale?: string): RegisteredElement | null {
84-
const key = this.createRegistryKey(entryId, fieldApiId, locale);
81+
getElement(entryId: string, fieldApiId?: string): RegisteredElement | null {
82+
const key = this.createRegistryKey(entryId, fieldApiId);
8583
const elements = this.registry[key];
8684
return elements?.[0] || null;
8785
}
@@ -132,7 +130,6 @@ export class FieldRegistry {
132130
attributeFilter: [
133131
'data-hygraph-entry-id',
134132
'data-hygraph-field-api-id',
135-
'data-hygraph-field-locale',
136133
'data-hygraph-component-chain',
137134
],
138135
});
@@ -162,19 +159,17 @@ export class FieldRegistry {
162159
if (!entryId) return;
163160

164161
const fieldApiId = element.getAttribute('data-hygraph-field-api-id') || undefined;
165-
const locale = element.getAttribute('data-hygraph-field-locale') || undefined;
166162
const componentChainRaw = element.getAttribute('data-hygraph-component-chain') || undefined;
167163

168164
const registeredElement: RegisteredElement = {
169165
element,
170166
entryId,
171167
fieldApiId,
172-
locale,
173168
componentChainRaw,
174169
lastUpdated: Date.now(),
175170
};
176171

177-
const key = this.createRegistryKey(entryId, fieldApiId, locale);
172+
const key = this.createRegistryKey(entryId, fieldApiId);
178173

179174
// Initialize array if it doesn't exist
180175
if (!this.registry[key]) {
@@ -195,7 +190,6 @@ export class FieldRegistry {
195190
console.log(`[FieldRegistry] Registered element:`, {
196191
entryId,
197192
fieldApiId,
198-
locale,
199193
element: element.tagName,
200194
});
201195
}
@@ -222,10 +216,9 @@ export class FieldRegistry {
222216
}
223217
}
224218

225-
private createRegistryKey(entryId: string, fieldApiId?: string, locale?: string): RegistryKey {
219+
private createRegistryKey(entryId: string, fieldApiId?: string): RegistryKey {
226220
const parts = [entryId];
227221
if (fieldApiId) parts.push(fieldApiId);
228-
if (locale) parts.push(locale);
229222
return parts.join(':');
230223
}
231224

src/core/OverlayManager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,12 @@ export class OverlayManager {
193193
// Get registered element data
194194
const entryId = hygraphElement.getAttribute('data-hygraph-entry-id');
195195
const fieldApiId = hygraphElement.getAttribute('data-hygraph-field-api-id');
196-
const locale = hygraphElement.getAttribute('data-hygraph-field-locale');
197196

198197
if (entryId) {
199198
const registeredElement: RegisteredElement = {
200199
element: hygraphElement,
201200
entryId,
202201
fieldApiId: fieldApiId || undefined,
203-
locale: locale || undefined,
204202
};
205203

206204
// Show overlay immediately

src/core/Preview.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,9 @@ export class Preview {
258258
const entryId = element.getAttribute('data-hygraph-entry-id');
259259
const fieldApiId = element.getAttribute('data-hygraph-field-api-id');
260260
const format = element.getAttribute('data-hygraph-rich-text-format') as RichTextFormatType;
261-
const locale = element.getAttribute('data-hygraph-field-locale') || '';
262261

263262
if (entryId && fieldApiId && format && ['html', 'markdown', 'text'].includes(format)) {
264-
const fieldKey = `${entryId}:${fieldApiId}:${locale}`;
263+
const fieldKey = `${entryId}:${fieldApiId}`;
265264

266265
// Check for duplicate field usage (UNSUPPORTED)
267266
if (formatPreferences[fieldKey]) {
@@ -373,29 +372,26 @@ export class Preview {
373372
entryId: message.entryId,
374373
fieldApiId: message.fieldApiId,
375374
componentChain: message.componentChain,
376-
locale: message.locale,
377375
});
378376

379377
// Emit event for listeners
380378
this.emitEvent('preview:field-focus', {
381379
entryId: message.entryId,
382380
fieldApiId: message.fieldApiId,
383-
locale: message.locale,
384381
});
385382

386383
// Use custom handler if provided
387384
if (this.config.onFieldFocus) {
388385
console.log('[Preview] Using custom onFieldFocus handler');
389-
this.config.onFieldFocus(message.fieldApiId, message.locale);
386+
this.config.onFieldFocus(message.fieldApiId);
390387
return;
391388
}
392389

393390
// Default behavior: Find and focus the specific field element for this entry
394391
console.log('[Preview] Searching for field in registry...');
395392
let elements = this.fieldRegistry.getElementsForEntryField(
396393
message.entryId,
397-
message.fieldApiId,
398-
undefined // locale not supported yet
394+
message.fieldApiId
399395
);
400396

401397
console.log('[Preview] Initial registry search result:', {
@@ -462,7 +458,6 @@ export class Preview {
462458
entryId: message.entryId,
463459
fieldApiId: message.fieldApiId,
464460
componentChain: message.componentChain,
465-
locale: message.locale,
466461
});
467462

468463
// Debug: Log all registered elements
@@ -529,7 +524,6 @@ export class Preview {
529524
private handleIframeEditClick(element: HTMLElement): void {
530525
const entryId = element.getAttribute('data-hygraph-entry-id');
531526
const fieldApiId = element.getAttribute('data-hygraph-field-api-id') || undefined;
532-
const locale = element.getAttribute('data-hygraph-field-locale') || undefined;
533527
const componentChain = this.parseComponentChain(
534528
element.getAttribute('data-hygraph-component-chain') || undefined
535529
);
@@ -542,7 +536,6 @@ export class Preview {
542536
type: 'field-click',
543537
entryId,
544538
fieldApiId,
545-
locale,
546539
componentChain,
547540
timestamp: Date.now(),
548541
};
@@ -562,16 +555,14 @@ export class Preview {
562555
this.emitEvent('preview:field-click', {
563556
entryId,
564557
fieldApiId,
565-
locale,
566-
componentChain,
558+
componentChain,
567559
mode: this.mode
568560
});
569561
}
570562

571563
private handleStandaloneEditClick(element: HTMLElement): void {
572564
const entryId = element.getAttribute('data-hygraph-entry-id');
573565
const fieldApiId = element.getAttribute('data-hygraph-field-api-id') || undefined;
574-
const locale = element.getAttribute('data-hygraph-field-locale') || undefined;
575566
const componentChain = this.parseComponentChain(
576567
element.getAttribute('data-hygraph-component-chain') || undefined
577568
);
@@ -584,7 +575,7 @@ export class Preview {
584575
}
585576

586577
// Construct Studio resource route URL
587-
const studioUrl = this.buildStudioUrl(entryId, fieldApiId, locale, componentChain);
578+
const studioUrl = this.buildStudioUrl(entryId, fieldApiId, componentChain);
588579

589580
// Open in new tab
590581
window.open(studioUrl, '_blank', 'noopener,noreferrer');
@@ -597,21 +588,19 @@ export class Preview {
597588
this.emitEvent('preview:field-click', {
598589
entryId,
599590
fieldApiId,
600-
locale,
601591
componentChain,
602592
mode: this.mode
603593
});
604594
}
605595

606-
private buildStudioUrl(entryId: string, fieldApiId?: string, locale?: string, componentChain?: ComponentChainLink[]): string {
596+
private buildStudioUrl(entryId: string, fieldApiId?: string, componentChain?: ComponentChainLink[]): string {
607597
const baseUrl = (this.config.studioUrl || 'https://app.hygraph.com').replace(/\/+$/, '');
608598
const params = new URLSearchParams({
609599
endpoint: this.config.endpoint,
610600
entryId,
611601
});
612602

613603
if (fieldApiId) params.set('fieldApiId', fieldApiId);
614-
if (locale) params.set('locale', locale);
615604
if (componentChain && componentChain.length > 0) {
616605
params.set('componentChain', JSON.stringify(componentChain));
617606
}

src/core/attributes.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ describe('attributes helpers', () => {
1313
const attributes = createPreviewAttributes({
1414
entryId: 'entry-1',
1515
fieldApiId: 'title',
16-
locale: 'en',
1716
});
1817

1918
expect(attributes).toEqual({
2019
'data-hygraph-entry-id': 'entry-1',
2120
'data-hygraph-field-api-id': 'title',
22-
'data-hygraph-field-locale': 'en',
2321
});
2422
});
2523

src/core/attributes.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import type { ComponentChainLink, ElementAttributes } from '../types';
33
export interface PreviewFieldOptions {
44
entryId: string;
55
fieldApiId?: string;
6-
locale?: string;
76
componentChain?: ComponentChainLink[];
87
}
98

109
export function createPreviewAttributes(options: PreviewFieldOptions): ElementAttributes {
11-
const { entryId, fieldApiId, locale, componentChain } = options;
10+
const { entryId, fieldApiId, componentChain } = options;
1211

1312
if (!entryId) {
1413
throw new Error('[Preview SDK] createPreviewAttributes requires an entryId');
@@ -22,10 +21,6 @@ export function createPreviewAttributes(options: PreviewFieldOptions): ElementAt
2221
attributes['data-hygraph-field-api-id'] = fieldApiId;
2322
}
2423

25-
if (locale) {
26-
attributes['data-hygraph-field-locale'] = locale;
27-
}
28-
2924
const serializedChain = serializeComponentChain(componentChain);
3025
if (serializedChain) {
3126
attributes['data-hygraph-component-chain'] = serializedChain;

src/react/HygraphPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface HygraphPreviewProps extends PreviewConfig {
2626
onDisconnected?: () => void;
2727
onSave?: SaveCallback;
2828
onError?: (error: Error) => void;
29-
onFieldFocus?: (fieldApiId: string, locale?: string) => void;
29+
onFieldFocus?: (fieldApiId: string) => void;
3030
onFieldUpdate?: (update: import('../types').FieldUpdate) => void;
3131
}
3232

src/react/HygraphPreviewNextjs.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ export interface HygraphPreviewNextjsProps extends Omit<HygraphPreviewProps, 'on
2525
* Optional custom field focus handler
2626
* Override the default behavior when Studio requests field focus
2727
* @param fieldApiId - The field API ID to focus
28-
* @param locale - The locale of the field (if applicable)
2928
*/
30-
onFieldFocus?: (fieldApiId: string, locale?: string) => void;
29+
onFieldFocus?: (fieldApiId: string) => void;
3130

3231
/**
3332
* Optional custom field update handler

0 commit comments

Comments
 (0)