Skip to content

Commit 2efbc03

Browse files
committed
fix: add script.onload handler in React/Vue examples
Fixes race condition where renderGitHubWidget() is called before the DOM element exists. Now explicitly calls render after script loads. https://github.com/iamjr15/github-contribution-graph
1 parent 98fc856 commit 2efbc03

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ const ContributionGraph = ({ username }) => {
175175
const script = document.createElement('script');
176176
script.src = 'https://github-contribution-graph.netlify.app/assets/js/gh.js';
177177
script.async = true;
178+
script.onload = () => {
179+
// Render after script loads and DOM is ready
180+
if (window.renderGitHubWidget) {
181+
window.renderGitHubWidget();
182+
}
183+
};
178184
document.body.appendChild(script);
179185

180186
return () => {
@@ -217,6 +223,12 @@ onMounted(() => {
217223
script = document.createElement('script');
218224
script.src = 'https://github-contribution-graph.netlify.app/assets/js/gh.js';
219225
script.async = true;
226+
script.onload = () => {
227+
// Render after script loads and DOM is ready
228+
if (window.renderGitHubWidget) {
229+
window.renderGitHubWidget();
230+
}
231+
};
220232
document.body.appendChild(script);
221233
});
222234

0 commit comments

Comments
 (0)