-
Notifications
You must be signed in to change notification settings - Fork 994
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
Frontend: GitHub API requests may be invoked twice on package details page #12763
Comments
Thanks for this issue, confirmed that this indeed happens. |
The cause for this seems to be that the
That means that two controllers exist on the page. Each one is called once when the application's controllers are loaded. I don't yet have any recommendations for how to resolve that. Naively it seems like we should make one HTTP request before initializing the controllers -- or somehow add synchronization so that both controllers block on a shared, single HTTP request (and both utilize the same response data). |
From what I understand about For communication between controllers, DOM events are often recommended. So it would be possible for the (singleton) info-retrieval controller to perform the API request, store the relevant data in the DOM (for example, as data attributes), and then emit an event when that data is ready for consumption by the (multiple) info-display controllers. It would be important to make sure that the info-display controllers are subscribed to the relevant DOM event before the API response is received, so perhaps the flow-of-control could be (pseudocode):
Confirming the behaviour and timing of those calls would be important ( |
@di would you hypothetically accept a pull request to resolve this that uses no-framework browser JavaScript? (I'm wondering whether it'd be more straightforward to make a single HTTP |
I think a) this isn't a huge problem as it stands right now, and b) we're generally trying to move away from doing JS outside of our frontend framework. So I wouldn't not merge it, but it's probably just not a great use of your time! |
Thanks @jayaddison for tracking that down - I noticed it and didn't understand where it came from. I'm thinking the "actual problem" is that we include the HTML twice in the same page, and control which is visibile based on viewport. This bloats the HTML and triggers this behavior - since the controller is included twice, it's invoked twice. A better solution would be to reevaluate the grid/layouts in use and figure out how to better express both the desired desktop and mobile layouts reusing the same HTML blocks, and thus only having a single controller. |
Thanks @miketheman - agreed, consolidating the two navigation component lists into one would be a nice improvement here. I'm also exploring a shorter-term fix with the existing |
This approach didn't seem great to me after exploring it a little in #12773. Based on a sense that consolidating the two navigation lists could be tricky (both implementation-wise and maintenance-wise), I think that the next alternative to explore could be:
|
Describe the bug
On the package details page (for example, https://test.pypi.org/project/example/ ), the frontend JS application may make multiple requests to the GitHub API if the package contains URLs that look like links to GitHub repositories.
Expected behavior
A single network call to the GitHub API should occur for statistics retrieval.
To Reproduce
api.github.com
occurMy Platform
Firefox 102, Linux
Additional context
The controller code that manages this appears to load twice - maybe that could be the cause?
Also: multiple-
connect
-calls appears to be an expected behaviour of thestimulus
library that the controller uses: hotwired/stimulus#215 (comment) - perhaps migrating to theinitialize
function could help?The text was updated successfully, but these errors were encountered: