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

SUL23-491: Make global message a client-side component #167

Closed
wants to merge 1 commit into from

Conversation

imonroe
Copy link
Contributor

@imonroe imonroe commented Jul 15, 2024

READY FOR REVIEW

Summary

  • The Global Message component doesn't respond to changes on the backend until the nextjs cache is revalidated, and so the message doesn't show up on all pages, and doesn't appear or disappear as expected.
  • Here, we convert the Global Message component to a client-side component which revalidates with the graphql endpoint more frequently.

Review By (Date)

  • When does this need to be reviewed by?

Criticality

  • This is a bug they really want fixed.

Urgency

  • Normal

Review Tasks

Setup tasks and/or behavior to test

  1. Check out this branch
  2. delete the .next directory out of your FE to clear the build cache.
  3. yarn run dev
  4. set up a global message. Confirm it appears (after the 5 sec revalidation period. Change the message, confirm it changes. Turn off the message. Confirm it disappear.

Site Configuration Sync

  • n/a

Front End Validation

Backend / Functional Validation

Code

  • Are the naming conventions following our standards?
  • Does the code have sufficient inline comments?
  • Is there anything in this code that would be hidden or hard to discover through the UI?
  • Are there any code smells?
  • Are tests provided? eg (unit, behat, or codeception)

Code security

General

  • Is there anything included in this PR that is not related to the problem it is trying to solve?
  • Is the approach to the problem appropriate?

Affected Projects or Products

  • Does this PR impact any particular projects, products, or modules?

Associated Issues and/or People

  • JIRA ticket(s)
  • Other PRs
  • Any other contextual information that might be helpful (e.g., description of a bug that this PR fixes, new functionality that it adds, etc.)
  • Anyone who should be notified? (@mention them here)

Resources

Copy link

vercel bot commented Jul 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
su-library ✅ Ready (Inspect) Visit Preview Jul 15, 2024 7:48pm

const client = new GraphQLClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL + "/graphql", {
...requestConfig,
next: {
revalidate: 5, // revalidate every 5 seconds to catch updates as soon as possible.
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'm not sure that this is the right number here; there may be a better balance between BE requests and performance. I just set it to 5 sec for testing purposes.

Copy link
Contributor

Choose a reason for hiding this comment

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

This definitely is not good. This will cause every single page load to fetch every bit of data from Drupal. Resulting in millions of requests and slow page loads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I narrow this down so it only gets the config page for the global message instead of everything?

Copy link
Contributor

Choose a reason for hiding this comment

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

That will still increase requests for nearly every single page every user visits because it will fetch new config page data every 5 seconds.

import {getConfigPage} from "@/lib/gql/fetcher";
import {StanfordGlobalMessage} from "@/lib/gql/__generated__/drupal.d";
import {JSX} from "react";
"use client"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do this on client, not the server.

Copy link
Contributor

Choose a reason for hiding this comment

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

There should be no reason for a client component or fetching from the client.

@imonroe
Copy link
Contributor Author

imonroe commented Jul 15, 2024

I'm not sure this is the best solution here, but it seems more efficient than invalidating the caches for all the pages every time the message changes or gets activated/deactivated.

I'm certainly open to argument if there is a better way to do this.

Copy link
Contributor

@pookmish pookmish left a comment

Choose a reason for hiding this comment

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

What's the underlying problem?

@imonroe
Copy link
Contributor Author

imonroe commented Jul 15, 2024

On production, if you turn on a global message (or turn it off, or change it), those changes don't show up on the front-end unless you revalidate the build cache for all the pages.

@pookmish
Copy link
Contributor

Ok, this explains more why we are over the usage on Vercel. Invalidating the entire site is very bad for performance on both the front end and the backend. We need to find better ways than doing that. Typically it's just invalidating the cache for the config pages.

@pookmish
Copy link
Contributor

@imonroe see #168

@imonroe
Copy link
Contributor Author

imonroe commented Jul 17, 2024

This PR is superceded by #168 which fixes the problem without extra overhead.

@imonroe imonroe closed this Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants