p5.js
p5.js copied to clipboard
Fix duplicate p5.js init by checking window.p5 and skipping if alread…
…y loaded
Resolves #7687
Changes:
- Add check for
window.p5 instanceof p5before global binding - Skip initialization and warn if p5.js was already loaded
- Avoids errors from
Object.definePropertyredefinition - Fixes issue where multiple p5.js imports cause failures
Screenshots of the change:
PR Checklist
- [x ]
npm run lintpasses - [ ] Inline reference is included / updated
- [ ] Unit tests are included / updated
Hi @limzykenneth,Sorry for the late response—I’ve been busy with my semester exams. I made some changes to the code based on the previous discussion. Could you please take a look at it?
Now that I think about it, I'm not sure the idea I had would work as in this case p5 would just detect itself as having already been defined as window.p5 making initialization impossible. @VANSH3104 Have you tested the code here to see if it works?
@limzykenneth Yes, I did test the code, but unfortunately didn’t get the desired result. I think your concern about p5 being already attached to window.p5 and causing initialization issues might actually be what's happening here. I’m still experimenting to better understand the behavior
Hi @limzykenneth , I tested the changes again and I think the issue is fixed now. Please let me know if you notice anything I might have missed.