Plugin Web Panel does not refresh context when switching a branch

Hello,
We have a custom Web Panel at location “bitbucket.web.repository.browse.filebrowser.before”

This web panel displays correctly when the page is loaded, and uses the context branch (our com.atlassian.plugin.web.ContextProvider implementation uses the atRevisionRef param for rendering).

It works the first time the page is loaded, but it does not refresh when another branch is selected, since bitbucket only refreshes a partial of the view with AJAX.

I think It should probably refresh this panel as well, since the atRevisionRef is different.

Our bitbucket server version: 5.9.0

Thank you

:broken_heart:

Hi @eduardo.ramos.ibanez,

First of all, thanks for getting back to this ticket and apologies that no one tried to help you.
As you pointed out, the current web panel doesn’t refresh the value of plugin context when a new branch is selected. The reason for that is, the plugin point is rendered on server-side, and we don’t want to refresh the whole page.

What I think you could try to do is to get the current branch reference using the JS API in the browser:

const stateUtils = require('bitbucket/util/state');
const currentRef = stateUtils.getRef();

This code will return an entity object that contains information about currently selected repository, branch, and git reference metadata including e.g. git commit hash.

Here is the link to the API documentation:

Let me know if that helps or in case you have more questions.

Thanks,
Maciej Adamczak
Bitbucket Developer

Thank you Maciej.

We use a web-panel with a .vm template, like

Unfortunately this requires us to rewrite the widget using the javascript (client-web-panel) way, right?
I tried to do that in the past but I could not make it work, using this documentation: https://developer.atlassian.com/server/bitbucket/reference/plugin-module-types/client-web-panel/

Could you please show me a full example of how to do it correctly, specially what needs to be included in atlassian-plugin.xml file. A minimal reproducible example of a plugin would be awesome.

Thanks,
Eduardo

Hi @eduardo.ramos.ibanez sorry for keeping you waiting but I was on holidays last weeks.

I managed to create a basic example for you. You can keep using web panels if you want. The code is a bit hacky since we need to listen to the browser URL changes and there is no optimal solution for that. You can take a look at the demo here:

Here is the link to the source code:

I hope I understood your use case correctly :slight_smile:

Thanks,
Maciej Adamczak
Atlassian Developer

Are there any official events we can listen on? Looking at the source of bitbucket, most (all?) say DO_NOT_USE.

I have a bunch of similar use cases and have solved them usually by listening to actual changes in the dom… it’s a lot of overhead code though.

Hi Maciej,

Thank you very much for your example plugin, I will try doing something like that.

Regards,
Eduardo

1 Like

Hi @jan, the DO_NOT_USE events don’t have the same type of support as any other plugin APIs in the product. Bitbucket team can change and/or remove those events at any point in time.

If you wish to request the official support for some of the events, you can create a feature request ticket on this page: https://jira.atlassian.com/browse/BSERV

Thanks,
Maciej Adamczak