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

Fix student quotes mismatch quote urls #2647

Merged

Conversation

DukeManh
Copy link
Contributor

@DukeManh DukeManh commented Jan 6, 2022

Fixes #2646.

The bug happens because we generate a random quote at

const studentQuote = quotes[Math.floor(Math.random() * quotes.length)];
.

Because NextJS tries to pre-render stuff, first, a random quote is generated once at build time, and once when the page loads. Now the new quote is updated to the visual elements of the page but not the href of the <a> tag which is still the pre-rendered one. I am not sure why the href is not updated.

In this fix, I put the random quote to a state, and generate it once the banner component is loaded. I could also generate it in the useState initializer but the initializer might be invoked twice because of React development strict mode.

Issue This PR Addresses

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

@gitpod-io
Copy link

gitpod-io bot commented Jan 6, 2022

@DukeManh
Copy link
Contributor Author

DukeManh commented Jan 6, 2022

cc @chrispinkney, I couldn't request a review, I think Chris was kicked out of Telescope :).

@humphd humphd requested a review from chrispinkney January 6, 2022 14:13
@humphd
Copy link
Contributor

humphd commented Jan 6, 2022

cc @chrispinkney, I couldn't request a review, I think Chris was kicked out of Telescope :).

Fixed

@DukeManh DukeManh merged commit cfc8f8f into Seneca-CDOT:master Jan 6, 2022
@DukeManh
Copy link
Contributor Author

DukeManh commented Jan 6, 2022

uh oh, looks like the problem still persists on staging.

@manekenpix
Copy link
Member

@DukeManh Weird, the fix worked with the vercel preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Landing page hero-banner quote does not properly link to the appropriate blog post
4 participants