react three fiber scene lagging on windows when keyboard keys are held down

I have a next JS app that is using react through fiber to create and render a scene with a model of an airplane. I have an array that contains about 50,000 objects that describe the airplanes position and rotation. I’m using the use frame hook to set an active index based on how much time has passed in between frames.

  useFrame((state, delta) => {
      console.log("setting active index");
      if (!isPaused) {
        const frameDelta =
          delta * speedFactor * sampleRate + roundingError.current;
        const roundedFrameDelta = Math.round(frameDelta);
        roundingError.current = frameDelta - roundedFrameDelta;
        setActiveIndex((prevIndex: number) => prevIndex + roundedFrameDelta);
      }
  });

This hook updates the active index in a Zustand store and as a side effect the airplanes position in Zustand gets updated as well.

      setActiveIndex: (newIndex) => {
        set({activeIndex: newIndex});
        get().setAirplanePositionAndRotation();
      },

Generally this solution works and the airplane flies around the scene if you are on windows and you hold down any key on the keyboard the airplane doesn’t fly around the scene anymore. I know that the frame rate isn’t dropping because the plane has a propeller on it that is spinning. This is also using the use frame hook and just updates its rotation each frame to spend the propeller. Also the console.log(“setting active index”) is still logging 33 times per second, however, if I console log the airplane position from the scene component there are no updates.

(neiter work when holding a key down, useFrame logs the same position, useEffect logs nothing, aerplane position not updating)

        const {
          airplanePosition,
        } = useAcroStore((state) => ({
          airplanePosition: state.airplanePosition,
        }));

        useFrame(() => {
          console.log(airplanePosition);
        });

        useEffect(() => { 
          console.log(airplanePosition);
        }, [airplanePosition]);

console of not working

The super confusing thing is that if I console log the same variable, airplanePosition, from the same Zustand store from a different component that does not use react three fiber, the airplane position variable is updating as it should.

(same code, different component, no useFrame as this component doesn’t use react three fiber. this print just fine when a key is held down. )

        const {
          airplanePosition,
        } = useAcroStore((state) => ({
          airplanePosition: state.airplanePosition,
        }));

        useEffect(() => { 
          console.log(airplanePosition);
        }, [airplanePosition]);

console working

Why would holding a key down prevent the airplane position from updating in react three fiber components but not in other components? And why might this only be happening on windows computers. I’ve tried multiple browsers and the same issue occurs, only on windows. I have also removed all event listeners and keyboard handlers from the app and still the same issue occurs.

Ive tried multiple browsers and the issue is the same. Ive tried removing all onKeyDown and all document.adeventListener("keydown") event listeners. this issue happens both in dev and in production environments

New contributor

user26448156 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật