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: links in tools section to specific category do not work #3116

Merged
merged 25 commits into from
Sep 14, 2024

Conversation

JeelRajodiya
Copy link
Contributor

@JeelRajodiya JeelRajodiya commented Jul 25, 2024

Description

When you go to url (enter url directly in the browser) https://www.asyncapi.com/tools#Converters it will not scroll to the Converters element
This PR closes #2181

input

Deployed version of this PR: https://deploy-preview-3116--asyncapi-website.netlify.app/tools#Directories

Copy link

netlify bot commented Jul 25, 2024

Deploy Preview for asyncapi-website ready!

Name Link
🔨 Latest commit 4360d98
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/66e54195b343e700081b9b1d
😎 Deploy Preview https://deploy-preview-3116--asyncapi-website.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.

@JeelRajodiya JeelRajodiya changed the title Fix: Links in tools section to specific category do not work fix: Links in tools section to specific category do not work Jul 25, 2024
@JeelRajodiya JeelRajodiya changed the title fix: Links in tools section to specific category do not work fix: links in tools section to specific category do not work Jul 25, 2024
@@ -1,5 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import TextTruncate from 'react-text-truncate';
Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Jul 25, 2024

Choose a reason for hiding this comment

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

TextTruncate library caused layout shifts post-render, prevented to add consistent scroll padding. If I'd kept TextTruncate, I would need inconsistent scroll padding. The further down the tools page I went, the more padding I'd need for each element.

So yes, changes in this file are relevant to the issue.

Comment on lines -52 to -59
useEffect(() => {
setLoading(true);
setTimeout(() => {
setLoading(false);
}, 1000);
}, []);

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Jul 25, 2024

Choose a reason for hiding this comment

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

I have removed this timeout and the loading state. Not sure why it was there before. Let me know if anything breaks because of this

Comment on lines 143 to 157
useEffect(() => {
const { hash } = window.location;

if (hash) {
const elementID = decodeURIComponent(hash.slice(1));
const element = document.getElementById(elementID);

if (element) {
document.documentElement.style.scrollPaddingTop = '6rem';
element.scrollIntoView({ behavior: 'smooth' });
document.documentElement.style.scrollPaddingTop = '0';
}
}
}, []);
// Function to update the list of tools according to the current filters applied
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual logic to scroll to the element. The padding is removed afterward so that it does not interfere with the other parts of the website

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Jul 25, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 43
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3116--asyncapi-website.netlify.app/

@JeelRajodiya
Copy link
Contributor Author

The PR is ready to review!

@JeelRajodiya
Copy link
Contributor Author

@akshatnema PTAL

@sambhavgupta0705
Copy link
Member

@akshatnema @anshgoyalevil PTAL
I checked this deploy functioning on web and mobile and it is working fine 🚀

@sambhavgupta0705
Copy link
Member

/update

@sambhavgupta0705
Copy link
Member

@akshatnema PTAL

const element = document.getElementById(elementID);

if (element) {
document.documentElement.style.scrollPaddingTop = '6rem';
Copy link
Member

Choose a reason for hiding this comment

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

Instead of directly modifying the DOM, can't we use inbuilt hooks of react to interact with virtual DOM?

Modifying real DOM in react is a bad practice.

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Aug 26, 2024

Choose a reason for hiding this comment

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

Agree! We are now using react refs to focus the category divs (I have pushed the changes).
but for the scroll padding we need the body element, I will have to pass the ref of the of the body element to ToolDashboard page. Should I go ahead and do it as well?

ref={descriptionRef}
className={`line-clamp-3 max-h-[4.5em] overflow-hidden text-ellipsis ${isTruncated && 'after:content-["..."]'}`}
>
{toolData.description}
Copy link
Member

Choose a reason for hiding this comment

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

How are we truncating the text here?

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Aug 26, 2024

Choose a reason for hiding this comment

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

The text is truncated using line-clamp-3, which limits the text to three lines. If isTruncated is true, the after:content-["..."] adds ellipsis (...) after the truncated text.

The styles max-h-[4.5em] overflow-hidden text-ellipsis are not relevant. I have removed them in the latest commit. Apologies for adding them initially.

Comment on lines -160 to -164
useEffect(() => {
updateToolsList();
}, [isPaid, isAsyncAPIOwner, languages, technologies, categories, searchName]);

Copy link
Member

Choose a reason for hiding this comment

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

Why you removed this useEffect? It's important to apply filters on Tools dashboard.

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Aug 26, 2024

Choose a reason for hiding this comment

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

I have moved the filter logic into a useMemo hook (please check here). The purpose of using useMemo is to avoid storing the tools list in a React state. Initially, when we used React state, the tools list took some time to appear after the page loaded, which made scrolling difficult.

I can ensure that the filters are still being applied.

Comment on lines 228 to 231
{loading ? (
<div className='mx-auto my-24 flex w-fit animate-pulse gap-4 text-black'>
<img src={loader} alt='loading' className='mx-auto w-16' />
<div className='my-auto text-xl'>Loading Tools...</div>
</div>
) : (
Copy link
Member

Choose a reason for hiding this comment

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

We want loading inside tools dashboard or lazy loading because there are too much content to show in the tools dashboard page. Not applying any preloader will give blank screen to the user, on first interaction with page.

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Aug 26, 2024

Choose a reason for hiding this comment

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

Akasht, Could you please visit the deployed version of this PR?
https://deploy-preview-3116--asyncapi-website.netlify.app/tools

We can keep the loading state, but based on the deployed version, I don't think it's necessary, as the content is instantly visible when the page loads.

Copy link
Member

Choose a reason for hiding this comment

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

Enable throttling inside your browser and you will then see a long wait with a white screen.

Copy link
Contributor Author

@JeelRajodiya JeelRajodiya Sep 5, 2024

Choose a reason for hiding this comment

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

Hello @akshatnema, Thanks for the suggestion. I have tried enabling throttling, and yes I did see a long wait with a white screen. However, when I switched to the master branch, the long wait screen was still there. Please see the below recordings.

Browser: Chrome (incognito tab)
Throttling: Fast 4G

On the master branch - White screen for ~9.83s

on-Master.mp4

On the fix-scroll-id branch (branch of current PR) - White screen for ~10.38s

on-PR.mp4

When I measured the time multiple times, it differed between 9.5s to 10.5s on both of the branches.

@JeelRajodiya
Copy link
Contributor Author

@akshatnema PTAL

@sambhavgupta0705
Copy link
Member

@akshatnema PTAL

@JeelRajodiya
Copy link
Contributor Author

@akshatnema PTAL

@akshatnema
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 7b23c07 into asyncapi:master Sep 14, 2024
15 checks passed
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.

Links in tools section to specific category do not work
4 participants