epam / ketcher

Web-based molecule sketcher
https://lifescience.opensource.epam.com/ketcher/demo.html
Apache License 2.0
505 stars 174 forks source link

After starting ketcher with value in smiles then broken zoom and centering #5882

Open hellhorse123 opened 1 month ago

hellhorse123 commented 1 month ago

https://github.com/user-attachments/assets/f1209b78-9cdb-4fa3-83a6-2cdc3b96295d

 useEffect(() => {
    if (ketcherInstance && isKetcherInitialized && defaultSmilesValue) {
      try {
        ketcherInstance.setMolecule(defaultSmilesValue);
      } catch (error) {
        console.error("Failed to set SMILES:", error);
        setHasError(true);
        setErrorMessage("Error setting molecule in Ketcher.");
      }
    }
  }, [defaultSmilesValue, isKetcherInitialized, ketcherInstance]);
  ...
        <Editor
          buttons={{
            sgroup: { hidden: true },
            images: { hidden: true },
            text: { hidden: true },
          }}
          staticResourcesUrl={process.env.PUBLIC_URL ?? "./"}
          structServiceProvider={structServiceProvider as any}
          errorHandler={(message: string | Error) => {
            console.error("Error in Ketcher:", message);
            setHasError(true);
            setErrorMessage(
              typeof message === "string" ? message : message.toString()
            );
          }}
          onInit={(ketcher: Ketcher) => {
            // Assign Ketcher instance to window for KetcherLogger to use
            window.ketcher = ketcher;
            if (!ketcherInstance) {
              // Проверяем, был ли уже инициализирован Ketcher
              setKetcherInstance(ketcher); // Set Ketcher instance in state
              setIsKetcherInitialized(true); // Mark Ketcher as initialized
              try {
                ketcher.setMolecule(defaultSmilesValue); // Set the default SMILES after initialization
              } catch (error) {
                console.error("Error initializing Ketcher with SMILES:", error);
                setHasError(true);
                setErrorMessage("Error initializing molecule in Ketcher.");
              }
            }
          }}
        />
Zhirnoff commented 1 month ago

@hellhorse123 Hi! Thank you for highlighting this issue. Please provide detailed steps for reproduce. Where you insert SMILES? Is this version of Ketcher embedded in a website?

hellhorse123 commented 3 weeks ago

@hellhorse123 Hi! Thank you for highlighting this issue. Please provide detailed steps for reproduce. Where you insert SMILES? Is this version of Ketcher embedded in a website?

No, this is antd Input with trackable state