haoxiang-xu / surface-editor

WebCodeEditor+LLMs is a state-of-the-art web-based Code Editor that leverages the power of large language models to assist in coding. By utilizing a vector database, it establishes intricate relationships between files and code segments.
0 stars 0 forks source link

Max Update Depth Warning #114

Closed haoxiang-xu closed 1 month ago

haoxiang-xu commented 1 month ago

After implement the memo wrapper for stack_frame

haoxiang-xu commented 1 month ago

due to <StackContainerWrapper mode={mode} command={command} data={data}> requires refactoring

haoxiang-xu commented 3 weeks ago

Problem happen because pop_command_by_id() will always change cmd when command length is 0.

  const pop_command_by_id = useCallback(
    (id) => {
      let popped_command = null;

      if (!cmd[id] || cmd[id].length === 0) {
        return popped_command;
      }

      setCmd((prevCommand) => {
        const updatedCommand = { ...prevCommand };
        if (updatedCommand[id] && updatedCommand[id].length > 0) {
          popped_command = updatedCommand[id].splice(0, 1)[0];

          if (updatedCommand[id].length === 0) {
            delete updatedCommand[id];
          }
        }
        return updatedCommand;
      });

      return popped_command;
    },
    [cmd]
  );

if statement added to prevent unneccessary rerender

haoxiang-xu commented 3 weeks ago

Still not fixing the problem, but the problem most likely happen in explorer or tag component https://typeofnan.dev/fix-the-maximum-update-depth-exceeded-error-in-react/