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

fix #3307: do nothing when calling init multiple times #3320

Merged
merged 3 commits into from
Mar 6, 2023

Conversation

erwanvivien
Copy link
Contributor

No description provided.

@Liamolucko Liamolucko linked an issue Feb 18, 2023 that may be closed by this pull request
Copy link
Collaborator

@Liamolucko Liamolucko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I think it may be a better idea to throw an error when init is called twice rather than silently returning, though - that's probably a mistake someone would want to know about, and I think it's a bit weird for the arguments that get passed to init to just be silently ignored.

@erwanvivien
Copy link
Contributor Author

I think you're right, if a maintainer wants the change, I'll do it!

@erwanvivien
Copy link
Contributor Author

In fact, I think it would break in React like website, as React launches startup function twice in dev mode, meaning init would get called twice, and it would break

However, having an error log might be great

@Liamolucko
Copy link
Collaborator

I don't really know anything about React. Is it not possible to just call init at the top level of the module, or keep track of whether you've called init yet and only call it if you haven't already?

@erwanvivien
Copy link
Contributor Author

You can keep track of course, and that's what apps use. However internally (and only in dev mode) they launch twice every component initialisation and destruction to assert you're cleaning the used items

I might be not clear, but it'll call init twice, I'm not 100% sure it would break, but it needs to be taken into account I guess?

@daxpedda
Copy link
Collaborator

Can we extend the same check to initSync?

I think you're right, if a maintainer wants the change, I'll do it!

Liamolucko has merge rights, currently he is probably your best bet to get anything merged in this repo.

@erwanvivien
Copy link
Contributor Author

Thanks for the heads up @daxpedda

@erwanvivien
Copy link
Contributor Author

In fact, I think it would break in React like website

More precision on this: It would not break React website. But I think it would break the dev workflow, see React Strict Mode.

Copy link
Collaborator

@Liamolucko Liamolucko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I can see how having it silently return would be a lot more convenient in situations like that, so I'll go ahead and merge this as-is. Thanks, and sorry I took so long to make up my mind...

Also, thanks @daxpedda for mentioning initSync, I had totally forgotten about it.

@Liamolucko Liamolucko merged commit 268fe64 into rustwasm:main Mar 6, 2023
@erwanvivien
Copy link
Contributor Author

It's alright, thanks 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent accidental re-initialization
3 participants