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(query-on-demand): loading indicator #28562

Merged
merged 13 commits into from
Dec 10, 2020
Merged

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Dec 9, 2020

This shows loading indicator in gatsby develop when using query on demand. It will show fixed element in bottom left if first render or navigation takes over 1s and dismiss it just before first render or when navigation completes.

TODO:

  • ability to disable it:
    • [x] permenently (gatsby-config) I backed out of it, because it sets precedent for configuration in flags which we might regret - it doesn't mean something like won't be added in the future - just that it needs more thinking and discussions
    • for current session
  • actually style indicator to match design language used for fast-refresh overlay
    Screenshot 2020-12-09 at 00 48 34
  • message in browser console after showing it for first time with instructions how to disable it
  • [ ] e2e tests indicator being shown in shadow-dom make it not feasible to test with our version of cypress - it seems like newer versions of cypress do support it, but upgrading cypress version is bigger lift and should be out of scope for this PR

Related Issues

closes #28182
[ch19091]

…akes over a second

this will show both for client side navigation and first render
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 9, 2020
@pieh pieh added topic: query on demand* and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Dec 9, 2020
@pieh pieh marked this pull request as ready for review December 10, 2020 14:47
if (!window.___gatsbyDidShowLoadingIndicatorBefore) {
// not ideal to this in render function, but that's just console info
debugLog(
`You might have seen "gatsby develop" loading indicator in the bottom left corner.\n\nIf you want to disable it you can visit ${window.location.origin}/___loading-indicator/disable (will disable it for current session).`
Copy link
Contributor

@pragmaticpat pragmaticpat Dec 10, 2020

Choose a reason for hiding this comment

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

Slight edit to the message:
A loading indicator is displayed in-browser whenever content is being requested upon navigation (Query On Demand). \n\nYou can disable the loading indicator for your current session by visiting ${window.location.origin}/___loading-indicator/disable

Copy link
Contributor

Choose a reason for hiding this comment

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

@pieh - what do you think of the minor edit? Do you think it misses any detail, or creates confusion?

Copy link
Contributor Author

@pieh pieh Dec 10, 2020

Choose a reason for hiding this comment

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

We do show loading indicator only if request doesn't finish within 1000 miliseconds - this is some "perceived performance" trick that I've read about somewhere that showing indicator immediately make it feels as less performant than it actually is (or maybe rather delaying showing indicator make it feel more performant) - I don't know if it's important to capture it in the message. So we show it when request is taking longer than what could be described as "almost instant" (maybe 1000 miliseconds is too high threshold for that, but we already do have precedent in using this value for some APIs that allow users to integrate their own custom loaders)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But overall - I think this is improvement over my message, so I will push update soon ;) And we can always iterate more if needed

if (!window.___gatsbyDidShowLoadingIndicatorBefore) {
// not ideal to this in render function, but that's just console info
debugLog(
`A loading indicator is displayed in-browser whenever content is being requested upon navigation (Query On Demand).\n\nYou can disable the loading indicator for your current session by visiting ${window.location.origin}/___loading-indicator/disable`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should also add a link to query on demand umrella here? @pragmaticpat @pieh

indicatorEnabled = true
writeVirtualLoadingIndicatorModule()
} else if (req.params.method === `disable` && indicatorEnabled !== false) {
indicatorEnabled = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to disable it for all develop sessions (i.e. save to cache)? Otherwise, users will have to disable it on every gatsby develop run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For permanent solution I would want to be able to configure this in gatsby-config - I even had this before, but it was setting precedence that we would have to stick with and it didn't feel right to do it in haste.

0a180e5 removed permanent setting

I did put note about this in description:

[x] permenently (gatsby-config) I backed out of it, because it sets precedent for configuration in flags which we might regret - it doesn't mean something like won't be added in the future - just that it needs more thinking and discussions

I don't like using this method to save permanently, because it's only thing that act this way and it's not clear to users how to re-enable it later.

Disabling for current session is mostly here to address potential issues of adding "foreign UI elements" to user sites - like iterating on e2e tests (i.e. cypress) in develop or running some other forms of automated audits with browser extensions etc.

Copy link
Contributor

@vladar vladar left a comment

Choose a reason for hiding this comment

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

Looks awesome 😍 Thanks! Left a couple of nits but nothing blocking - can address in the follow-up if required.

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.

there is no visual indicator when running long queries on demand
4 participants