Comments (6)
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.
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.
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
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.
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.
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.
Fixed by #716
from bitburner-src.
Related Issues (20)
- ns.stanek.acceptGift() always returns false since v2.5.2 HOT 2
- Feature request: Permit .json as a file extension HOT 1
- "Total production since last Augment Installation" value after offline period HOT 3
- CORPORATION: Some useful properties of materials/products are unobtainable through NS scripts
- Game sometime freezes when passing argument to script HOT 4
- Bug: Scripts displayed offline gains miscalculation HOT 3
- ns.formulas.work.companyGains() reports the reputation rates in the wrong order for the "Security" field. HOT 2
- Feature request: Obtain estimated success chance for sleeves performing Bladeburner Contracts in NS scripts
- Wrong output example for "Find All Valid Math Expressions" contract
- getAugmentationGraftTime returns incorrect value HOT 4
- autocomplete does not work well with multi-word data HOT 5
- Gang: Wanted level evolution value off by ca. 0.005/sec HOT 5
- Feature Request: NS function to obtain relations between location/company/organization HOT 2
- Show Multipliers in Stats calculated for current bitnode HOT 1
- Server's maximum money softcap message while spending hashes does not adjust to specified number format in options.
- Can't buy anything after buying first CSEC augmentation HOT 13
- Documentation page of List of Factions and their Requirements messed up by HTML labels HOT 2
- `getResetInfo` timestamps are incorrect at the start of the game HOT 1
- Location names in the new Job Info page mess up with each other when their servers are backdoored HOT 1
- Docs page for Faction Requirements doesn't currently use number formatting options HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitburner-src.