Skip to content

Conversation

@Justineo
Copy link
Member

@Justineo Justineo commented Feb 13, 2025

Summary

KM-952

Currently, our products usually follow the approach described in the Kongponents documentation, where revalidation is triggered by incrementing the fetcherCacheKey (although strictly speaking, this is not the correct method, as it actually caches data for the same query at different locations, which is loading new data instead of revalidation).

After adding the isLoading state for SWRV, <KTableData> also triggers the loading state when the fetcherCacheKey changes (which is technically correct, but the semantics of incrementing the fetcherCacheKey are slightly different). This is generally acceptable (for example, after adding or removing list items).

However, in certain scenarios like polling, we actually don’t want to trigger the loading state. But since we haven’t exposed the revalidate-related primitives, users can only achieve this by incrementing the fetcherCacheKey, which may lead to unexpected loading states. A quick workaround is for users to control the loading prop themselves to prevent the loading state during polling.

This PR implements a solution where, if the user passes the loading prop, it will always override the internal loading state of the component (which is also the expected behavior for the loading prop), helping users with a quick workaround.

Also updated Cypress to fix cypress-io/cypress#30715.

@netlify
Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kongponents-sandbox ready!

Name Link
🔨 Latest commit 6aecdf0
🔍 Latest deploy log https://app.netlify.com/sites/kongponents-sandbox/deploys/67e0c289b278d600071eb331
😎 Deploy Preview https://deploy-preview-2614--kongponents-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for kongponents ready!

Name Link
🔨 Latest commit 6aecdf0
🔍 Latest deploy log https://app.netlify.com/sites/kongponents/deploys/67e0c2890188d400080942ca
😎 Deploy Preview https://deploy-preview-2614--kongponents.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

:hide-pagination-when-optional="false"
:hide-toolbar="hideToolbar"
:loading="loading || fetcherIsLoading"
:loading="loading ?? fetcherIsLoading"
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/Kong/konnect-ui-apps/blob/37492e0dcbc48d8376d4cc06b1fdc0132203f0ea/apps/gateway-manager/src/pages/GatewayLogsPage.vue#L74

It appears that it’s common practice across our tables in Konnect to initialize a ref<boolean> that defaults to false for many of our KTableData instances.

Wouldn’t this usage pattern prevent the table’s built-in loading state from showing when it actually does need to initially fetch the data when a component mounts?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the linked implementation, each time fetcher is called, it triggers clearLoadingAndError, which sets isLoading to true. The logic seems a bit convoluted, but I assume the behavior remains consistent. We can confirm this by testing it in a preview PR.

Actually, I believe we’re misusing fetcherCacheKey to trigger revalidation like this. Instead, we should directly include the fetcher parameters in the cache key.

For the current change, if users explicitly set the loading prop to false, we should consider respecting that.

Copy link
Member Author

Choose a reason for hiding this comment

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

The behavior of the loading prop isn’t the core of the problem we’re facing. The key issue is that we haven’t exposed a “revalidate only” interface on the Table. The auto-incrementing cache key actually implies loading new data that hasn’t been loaded before, which, technically, is not accurate. Another viable solution is to defineExpose the revalidate method from <KTableData>, and also, for the scenario we’re currently encountering (polling), expose the refreshInterval configuration of SWRV as a prop. This way, we can trigger polling revalidation in a more declarative manner. WDYT?

@Justineo Justineo force-pushed the fix/table-loading branch from 64f3b7a to 6aecdf0 Compare March 24, 2025 02:25
@kongponents-bot
Copy link
Collaborator

Preview package from this PR in consuming application

In consuming application project install preview version of kongponents generated by this PR:

@kong/kongponents@pr-2614

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.

Your configFile is invalid with Node.js 22.12.0

3 participants