@shipstatic/drop 2.10.4-beta.6 → 2.10.4-beta.7

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.
package/dist/index.js CHANGED
@@ -1108,7 +1108,7 @@ var initialState = {
1108
1108
  };
1109
1109
  function useDrop({ ship }) {
1110
1110
  const [state, setState] = useState(initialState);
1111
- const isProcessingRef = useRef(false);
1111
+ const runRef = useRef(null);
1112
1112
  const folderInputRef = useRef(null);
1113
1113
  const filesInputRef = useRef(null);
1114
1114
  const isProcessing = state.phase === "processing";
@@ -1121,12 +1121,13 @@ function useDrop({ ship }) {
1121
1121
  const getFilesForUpload = useCallback(() => validFiles.map((f) => f.file), [validFiles]);
1122
1122
  const processFiles2 = useCallback(
1123
1123
  async (newFiles) => {
1124
- if (isProcessingRef.current) {
1124
+ if (runRef.current) {
1125
1125
  console.warn("File processing already in progress. Ignoring duplicate call.");
1126
1126
  return;
1127
1127
  }
1128
1128
  if (!newFiles || newFiles.length === 0) return;
1129
- isProcessingRef.current = true;
1129
+ const run = new AbortController();
1130
+ runRef.current = run;
1130
1131
  setState({
1131
1132
  ...initialState,
1132
1133
  phase: "processing",
@@ -1134,9 +1135,12 @@ function useDrop({ ship }) {
1134
1135
  });
1135
1136
  try {
1136
1137
  const outcome = await processFiles(newFiles, {
1137
- limits: await ship.getLimits(),
1138
- onStatus: (status) => setState((prev) => ({ ...prev, status }))
1138
+ limits: await ship.getLimits({ signal: run.signal }),
1139
+ onStatus: (status) => {
1140
+ if (!run.signal.aborted) setState((prev) => ({ ...prev, status }));
1141
+ }
1139
1142
  });
1143
+ if (run.signal.aborted) return;
1140
1144
  setState({
1141
1145
  phase: outcome.phase,
1142
1146
  isDragging: false,
@@ -1145,15 +1149,26 @@ function useDrop({ ship }) {
1145
1149
  status: outcome.status,
1146
1150
  needsBuild: outcome.needsBuild
1147
1151
  });
1152
+ } catch (error) {
1153
+ if (run.signal.aborted) return;
1154
+ setState({
1155
+ ...initialState,
1156
+ phase: "error",
1157
+ status: {
1158
+ title: "Processing Failed",
1159
+ details: error instanceof Error ? error.message : String(error)
1160
+ }
1161
+ });
1148
1162
  } finally {
1149
- isProcessingRef.current = false;
1163
+ if (runRef.current === run) runRef.current = null;
1150
1164
  }
1151
1165
  },
1152
1166
  [ship]
1153
1167
  );
1154
1168
  const reset = useCallback(() => {
1169
+ runRef.current?.abort();
1170
+ runRef.current = null;
1155
1171
  setState(initialState);
1156
- isProcessingRef.current = false;
1157
1172
  }, []);
1158
1173
  const handleDragOver = useCallback((e) => {
1159
1174
  e.preventDefault();