Symptoms:
- Model renders once, then the next frame throws the error.
- On route change or Collapse/Tab hide, the error repeats.
- Adding viewer.clear() in cleanup removes the message but stops
rendering completely.
Component code:
import React, { useRef, useEffect } from "react";
import * as $3Dmol from "3dmol";
export default function Protein3DMol({ pdbText }) {
const divRef = useRef(null);
useEffect(() => {
if (!divRef.current || !pdbText) return;
const viewer = $3Dmol.createViewer(divRef.current, { backgroundColor: "white" });
viewer.addModel(pdbText, "pdb");
viewer.setStyle({}, { cartoon: { color: "spectrum" } });
viewer.zoomTo();
viewer.render();
return () => {
viewer.clear();
const canvas = divRef.current.querySelector("canvas");
const gl = canvas?.getContext("webgl") || canvas?.getContext("experimental-webgl");
gl?.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [pdbText]);
return <div ref={divRef} style={{ width: "100%", height: "100%", minHeight: 300 }} />;
}
Fetch Logic:
fetch("https://two4-cp-backend.onrender.com/filtered_pdbs/{pdb}")
.then(res => res.text())
.then(setPdbText);
What I’ve tried:
- Wait for div.clientWidth && clientHeight before calling
createViewer. - Set minHeight: 300 on the container.
- Attach WEBGL_lose_context in cleanup.
- Disable GPU hardware acceleration.
(Error disappears, but 3D is of course disabled.)
How can I safely render a PDB string using 3Dmol.js without triggering GL_INVALID_FRAMEBUFFER_OPERATION in Brave and Firefox? I want to keep the rendering live and interactive, not just a static snapshot.

