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

clearRegions method has bug #3798

Open
panhe-xue opened this issue Jul 26, 2024 · 14 comments
Open

clearRegions method has bug #3798

panhe-xue opened this issue Jul 26, 2024 · 14 comments
Labels

Comments

@panhe-xue
Copy link
Contributor

Bug description

The regions array is not cleared after the clearRegions method is called

Environment

  • Browser: Chrome

Minimal code snippet

Expected result

Obtained result

Screenshots

image

@panhe-xue panhe-xue added the bug label Jul 26, 2024
@panhe-xue
Copy link
Contributor Author

image

@panhe-xue
Copy link
Contributor Author

this.regions.forEach((region) => (region && region.remove()))

@katspaugh
Copy link
Owner

Hmm, weird. Regions are supposed to be removed from the list on the remove event:

https://github.com/katspaugh/wavesurfer.js/blob/main/src/plugins/regions.ts#L581

@panhe-xue
Copy link
Contributor Author

So we can only remove regions using events, not clearRegions? Because clearRegions is going to be a problem next time.

@panhe-xue
Copy link
Contributor Author

Hmm, weird. Regions are supposed to be removed from the list on the remove event:

https://github.com/katspaugh/wavesurfer.js/blob/main/src/plugins/regions.ts#L581

So we can only remove regions using events, not clearRegions? Because clearRegions is going to be a problem next time

@katspaugh
Copy link
Owner

No, the event is emitted when a region is removed. So when clear regions removes each region, it's supposed to emit a remove event and get removed from the list.

@panhe-xue
Copy link
Contributor Author

No, the event is emitted when a region is removed. So when clear regions removes each region, it's supposed to emit a remove event and get removed from the list.

I see what you're said, How do I know when clearRegions has cleared all of them

@panhe-xue
Copy link
Contributor Author

No, the event is emitted when a region is removed. So when clear regions removes each region, it's supposed to emit a remove event and get removed from the list.

I see what you're said, How do I know when clearRegions has cleared all of them

I can only use other variables to control, I can't get this moment from an event???

@katspaugh
Copy link
Owner

You don't need to use the event. All I'm saying is that clearRegions is supposed to remove each region from the this.regions array thanks to an internal remove event subscription. If it doesn't, there might be a bug.

@panhe-xue
Copy link
Contributor Author

clearRegions

When clearRegions called, you should make sure that addRegions cannot be executed, otherwise it will get messy

@katspaugh
Copy link
Owner

katspaugh commented Jul 26, 2024

I see. You can probably call addRegion with a delay (setTimeout) as a workaround.

@panhe-xue
Copy link
Contributor Author

That doesn't work, I think of a way, could you have a look?

` public clearRegions() { // this.regions.forEach((region) => region.remove()) const regions = cloneDeep(this.regions) regions.forEach((region) => region.remove()) }

`
That doesn't work, I think of a way, could you have a look?

`
public clearRegions() {
// this.regions.forEach((region) => region.remove())
const regions = cloneDeep(this.regions)
this.regions = []
regions.forEach((region) => region.remove())
}

`

@lucastheis
Copy link
Contributor

I ran into the same issue and my workaround was this:

regionsPlugin.clearRegions();
regionsPlugin.regionsContainer.innerHTML = "";

@panhe-xue
Copy link
Contributor Author

I ran into the same issue and my workaround was this:

regionsPlugin.clearRegions();
regionsPlugin.regionsContainer.innerHTML = "";

I used id to delete it

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

No branches or pull requests

3 participants