Giter VIP home page Giter VIP logo

Comments (6)

Snarling avatar Snarling commented on July 23, 2024

Probably an issue in the component that handles displaying the contract, not cleaning up properly when forcibly closed (cleanup can be done via a useEffect return)

from bitburner-src.

myCatsName avatar myCatsName commented on July 23, 2024

Probably an issue in the component that handles displaying the contract, not cleaning up properly when forcibly closed (cleanup can be done via a useEffect return)

The location I'm looking at is https://github.com/bitburner-official/bitburner-src/blob/dev/src/ui/React/CodingContractModal.tsx#24

interface CodingContractProps { c: CodingContract; onClose: () => void; onAttempt: (answer: string) => void; }

and the promises referenced here https://github.com/bitburner-official/bitburner-src/blob/2c0f7f1eda8e0519e89f342a860830182892a83c/src/CodingContracts.ts#L156C10-L156C10

async prompt(): Promise<CodingContractResult> { return new Promise<CodingContractResult>((resolve) => { CodingContractEvent.emit({ c: this, onClose: () => { resolve(CodingContractResult.Cancelled); },

I have tried adding cleanup return to the modal component's existing useEffect, but can't get the right behavior at all. I think cleanup needs to resolve the contract as cancelled, maybe . Lack of React (and general code) experience and I might be missing other ideas. Examples I've tried (close() is a function within the CCT modal component)

useEffect(() => { CodingContractEvent.subscribe((props) => setContract(props)); return ()=>{close} },[]);

And other ways avoiding the close fx, for example

useEffect(() => { CodingContractEvent.subscribe((props) => setContract(props)); return ()=> {console.log('CCT modal unmount') ;setContract(null); contract?.onClose;} },[]);

PS, I will attach gotogym.txt, a js script I used to replicate the bug. run gotogym.js, leave the tail open; open a CCT; run gotogym.js using the tail; the CCT was forced shut and gotogym has moved focus back to terminal; Now, attempting to run a CCT will produce "there's already a contract in progress" bug.
gotogym.txt

from bitburner-src.

myCatsName avatar myCatsName commented on July 23, 2024

I think this is relevant console error for this bug: React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function

image

It seems specifically to appear the "next" time the CCT modal is opened (if possible) after a "focus interrupting" process was used, like my gotoGym script. In other words, run contract-756974.cct alone produces no error, run gotoGym.js no error. But if CCT is run and closed, then gotoGym is run (and finished), now re-opening CCT modal should show this error. No error if instead a "non-interrupting" script is run instead of gotoGym.

from bitburner-src.

myCatsName avatar myCatsName commented on July 23, 2024

I have a partial fix to the first part of this problem, and continuing work...

this is enough to cancel the contract when interrupted, eliminating the need to "refresh" BB to open a CCT modal. ATM the above console React error message is still thrown, so I am investigating. But happy to finally make a step in the right direction. I am also seeing discussion about the error message possibly being a React thing. IF the functional bugs are fixed, the error is in console only and may not affect the player. But currently this code causes other problems. I'm struggling to master useEffects lol

useEffect(() => {
CodingContractEvent.subscribe((props) => setContract(props));
return () => {contract?.onClose()};
},);

I'm thinking there need to be 2 useEffect functions, because the return function should do onClose and unsubscribe from the event props (possible fix for the React console error?) only on unmount and needs [] dependency; but the event subscriptions need to constantly render with no dependency array, or the input field is unusable and defaults back to terminal.

from bitburner-src.

myCatsName avatar myCatsName commented on July 23, 2024

OK I think I might have it here, with 2 useEffects I seem to have a fix.

useEffect(() => {
CodingContractEvent.subscribe((props) => setContract(props));
},);
useEffect(() => {
return () =>{contract?.onClose()};
},[contract]);

  • Input field works, submission pass fail works, copypaste works.
  • When the CCT modal is closed by interruption, terminal prints the contract was cancelled and can be re-opened as normal.
  • Tested with gotogym, .click(), and using the overview "focus" method, or alt+E to editor, all the situations described in the issue here.
  • Really should be tested by others, because I have had a variety of behaviors during the time I worked this out, some of which would be very undesired. I will post a PR soon after a bit of clean up

from bitburner-src.

Snarling avatar Snarling commented on July 23, 2024

Fixed by #716

from bitburner-src.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.