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

feat(docgen-sidebar): add polling to tags loading in dogen sidebar #3858

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

rustam-e
Copy link
Contributor

before:
if the template has been updated and tags have not been processed - user would see error state requesting them to click a refresh button

after:
components tries re-fetching up to 10 times and only then shows the error state

@rustam-e rustam-e requested review from a team as code owners January 21, 2025 14:39
abdel-ships-it
abdel-ships-it previously approved these changes Jan 27, 2025
Copy link

@abdel-ships-it abdel-ships-it left a comment

Choose a reason for hiding this comment

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

LGTM

tjuanitas
tjuanitas previously approved these changes Jan 28, 2025
abdel-ships-it
abdel-ships-it previously approved these changes Jan 29, 2025
Copy link

@abdel-ships-it abdel-ships-it left a comment

Choose a reason for hiding this comment

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

LGTM

setHasError(false);
} else {
const loadTags = useCallback(
async (attempts = 10) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we chose to go with 10 attempts? I feel like most of the time we do 3 - 5 attempts for retries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it often can take more than 5 seconds to process the document

@bfoxx1906 bfoxx1906 self-requested a review February 2, 2025 19:46
@@ -33,6 +33,8 @@ import commonMessages from '../../common/messages';
import './DocGenSidebar.scss';
import { DocGenTag, DocGenTemplateTagsResponse, JsonPathsMap } from './types';

const DEFAULT_RETRIES = 10;

Choose a reason for hiding this comment

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

10 retries is a lot. How did we come up with this number? Would it be better to have have a timeout to determine whether or not to throw an error instead? Just a question.

Copy link
Contributor Author

@rustam-e rustam-e Feb 3, 2025

Choose a reason for hiding this comment

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

the time to process the document can take a while (in practice single digit number of seconds, but can take longer) - I can reduce the retries and increase the delay between them but that'd the time till content for the user longer.

try {
const response: DocGenTemplateTagsResponse = await getDocGenTags();
if (response.message) {
setTimeout(() => {

Choose a reason for hiding this comment

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

Are we doing this because we need to wait a second before trying to call the getDocGenTags again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i wanted to reduce number of calls - without it if the end user has fast internet connection they'd make additional calls - e.g. more than 1 call / second which seems unnecessary. e.g. if it takes 5 seconds to process the document, with this approach we're sending 5 requests, but without it if the request completes in 0.5 seconds we'd be sending 10 requests and so on. A small optimisation, not critical

getDocGenTags: processingTagsMock,
});

await jest.advanceTimersByTime(1000);

Choose a reason for hiding this comment

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

I'm assuming there's a reason why we can't put this in a loop?

Copy link
Contributor Author

@rustam-e rustam-e Feb 3, 2025

Choose a reason for hiding this comment

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

https://eslint.org/docs/latest/rules/no-await-in-loop - I tried to use Promise.all approach but it didn't work

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.

6 participants