Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global state mutation in loader functions breaks multi-versioning in one process #3314

Open
extremeheat opened this issue Feb 22, 2024 · 3 comments
Labels
bug Stage3 idea is precisely specified, only coding is left to do

Comments

@extremeheat
Copy link
Member

extremeheat commented Feb 22, 2024

https://github.com/PrismarineJS/mineflayer/blob/7bb9ea09f2be4d9dc741beedc67625efe243438d/lib/bossbar.js

For example,

let ChatMessage
const colors = ['pink', 'blue', 'red', 'green', 'yellow', 'purple', 'white']
const divisions = [0, 6, 10, 12, 20]

module.exports = loader

function loader (registry) {
  ChatMessage = require('prismarine-chat')(registry)
  return BossBar
}

class BossBar {
  constructor (uuid, title, health, dividers, color, flags) {
    this._entityUUID = uuid
    this._title = new ChatMessage(JSON.parse(title))
    this._health = health

will result in all BossBar classes having their ChatMessage being updated to whatever the last caller to loader() specified. In this case it's a special case because the constructor is only called once, but in other places it will cause unexpected behaviours, like here https://github.com/PrismarineJS/mineflayer/blob/b9491ae508dc52e4538dd66eb6f47a639facde20/lib/team.js

@extremeheat extremeheat added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Feb 22, 2024
@rom1504
Copy link
Member

rom1504 commented Feb 22, 2024

Indeed! I guess we should follow the same loader pattern as in prismarine-* classes

@rom1504
Copy link
Member

rom1504 commented Feb 26, 2024

Is this fixed now @extremeheat ?

@extremeheat
Copy link
Member Author

Seems like prismarine-recipe still has issue https://github.com/PrismarineJS/prismarine-recipe/blob/master/lib/recipe.js

Maybe some others, I just did a quick search for loader functions in the org

@rom1504 rom1504 added bug Stage3 idea is precisely specified, only coding is left to do and removed possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Stage3 idea is precisely specified, only coding is left to do
Projects
None yet
Development

No branches or pull requests

2 participants