mirror of
https://github.com/stan-smith/FossFLOW.git
synced 2025-12-27 00:19:14 -05:00
fix: resolve connector persistence issues (#110)
- Remove validation checks that were deleting valid connectors - Add deep comparison to prevent unnecessary reloads - Fix state synchronization issue where connectors were being overwritten Co-authored-by: Stan <stanleylsmith@pm.me> fixes #103 (hopefully)
This commit is contained in:
@@ -32,6 +32,19 @@ export const useInitialDataManager = () => {
|
||||
(_initialData: InitialData) => {
|
||||
if (!_initialData || prevInitialData.current === _initialData) return;
|
||||
|
||||
// Deep comparison to prevent unnecessary reloads when data hasn't actually changed
|
||||
if (prevInitialData.current) {
|
||||
const prevConnectors = JSON.stringify(prevInitialData.current.views?.[0]?.connectors || []);
|
||||
const newConnectors = JSON.stringify(_initialData.views?.[0]?.connectors || []);
|
||||
const prevItems = JSON.stringify(prevInitialData.current.items || []);
|
||||
const newItems = JSON.stringify(_initialData.items || []);
|
||||
|
||||
if (prevConnectors === newConnectors && prevItems === newItems) {
|
||||
// Data hasn't actually changed, skip reload
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setIsReady(false);
|
||||
|
||||
const validationResult = modelSchema.safeParse(_initialData);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Connector } from 'src/types';
|
||||
import { produce } from 'immer';
|
||||
import { getItemByIdOrThrow, getConnectorPath, getAllAnchors } from 'src/utils';
|
||||
import { validateConnector } from 'src/schemas/validation';
|
||||
import { getItemByIdOrThrow, getConnectorPath } from 'src/utils';
|
||||
import { State, ViewReducerContext } from './types';
|
||||
|
||||
export const deleteConnector = (
|
||||
@@ -26,25 +25,26 @@ export const syncConnector = (
|
||||
const newState = produce(state, (draft) => {
|
||||
const view = getItemByIdOrThrow(draft.model.views, viewId);
|
||||
const connector = getItemByIdOrThrow(view.value.connectors ?? [], id);
|
||||
const allAnchors = getAllAnchors(view.value.connectors ?? []);
|
||||
const issues = validateConnector(connector.value, {
|
||||
view: view.value,
|
||||
model: state.model,
|
||||
allAnchors
|
||||
});
|
||||
|
||||
if (issues.length > 0) {
|
||||
const stateAfterDelete = deleteConnector(id, { viewId, state: draft });
|
||||
|
||||
draft.scene = stateAfterDelete.scene;
|
||||
draft.model = stateAfterDelete.model;
|
||||
} else {
|
||||
|
||||
// Skip validation - allow all connectors regardless of position
|
||||
try {
|
||||
const path = getConnectorPath({
|
||||
anchors: connector.value.anchors,
|
||||
view: view.value
|
||||
});
|
||||
|
||||
draft.scene.connectors[connector.value.id] = { path };
|
||||
} catch (error) {
|
||||
// Even if we can't get the path, keep the connector with an empty path
|
||||
draft.scene.connectors[connector.value.id] = {
|
||||
path: {
|
||||
tiles: [],
|
||||
rectangle: {
|
||||
from: { x: 0, y: 0 },
|
||||
to: { x: 0, y: 0 }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user