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