Skip to content

Commit 99ba9bd

Browse files
committed
fix: update data source initialization to use base URL and prevent loading flash in ObjectForm
1 parent 963f512 commit 99ba9bd

5 files changed

Lines changed: 12 additions & 6 deletions

File tree

apps/console/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function AppContent() {
5050
async function initializeDataSource() {
5151
try {
5252
const adapter = new ObjectStackAdapter({
53-
baseUrl: '/',
53+
baseUrl: '/api/v1',
5454
autoReconnect: true,
5555
maxReconnectAttempts: 5,
5656
reconnectDelay: 1000,

apps/console/src/__tests__/ObjectForm.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('ObjectForm with MSW Integration', () => {
2828
client = new ObjectStackClient({ baseUrl: 'http://localhost:3000' } as any);
2929
await client.connect();
3030

31-
dataSource = new ObjectStackDataSource(client as any);
31+
dataSource = new ObjectStackDataSource({ baseUrl: 'http://localhost:3000' });
3232

3333
// Get a valid contact ID for edit tests
3434
const driver = getDriver();

apps/console/src/__tests__/ObjectGrid.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('ObjectGrid MSW Integration', () => {
2020
await startMockServer();
2121
client = new ObjectStackClient({ baseUrl: 'http://localhost:3000' } as any);
2222
await client.connect();
23-
dataSource = new ObjectStackDataSource(client as any);
23+
dataSource = new ObjectStackDataSource({ baseUrl: 'http://localhost:3000' });
2424
});
2525

2626
afterAll(() => {

apps/console/src/__tests__/ObjectGridInteractions.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('ObjectGrid Interactions', () => {
3030
await startMockServer();
3131
client = new ObjectStackClient({ baseUrl: 'http://localhost:3000' } as any);
3232
await client.connect();
33-
dataSource = new ObjectStackDataSource(client as any);
33+
dataSource = new ObjectStackDataSource({ baseUrl: 'http://localhost:3000' });
3434
});
3535

3636
afterAll(() => {

packages/plugin-form/src/ObjectForm.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,14 @@ export const ObjectForm: React.FC<ObjectFormProps> = ({
402402
});
403403

404404
setFormFields(generatedFields);
405-
setLoading(false);
406-
}, [objectSchema, schema.fields, schema.customFields, schema.readOnly, schema.mode, hasInlineFields]);
405+
406+
// Only set loading to false if we are not going to fetch data
407+
// This prevents a flash of empty form before data is loaded in edit mode
408+
const willFetchData = !hasInlineFields && (schema.recordId && schema.mode !== 'create' && dataSource);
409+
if (!willFetchData) {
410+
setLoading(false);
411+
}
412+
}, [objectSchema, schema.fields, schema.customFields, schema.readOnly, schema.mode, hasInlineFields, schema.recordId, dataSource]);
407413

408414
// Handle form submission
409415
const handleSubmit = useCallback(async (formData: any, e?: any) => {

0 commit comments

Comments
 (0)