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: Fixing issue 309, which code block doesn't load all the time #326

Conversation

EddieSCJ
Copy link
Contributor

@EddieSCJ EddieSCJ commented Jan 20, 2024

Fix: Fixing issue 309, which code block doesn't load all the time

Description

Note: Since I'm not a frontend dev and doesn't work with frontend and react there are many years, I might say that something maybe will be incorrect, so, be kind and tell me that I will solve.

Once you reload, the next times the code will be loaded.

Problem

When using the morethan-log I saw that sometimes code blocks are loaded and sometimes it wasn't loaded, and found the #309 issue warning about this started to try solve it.

I also saw that the problem doesn't occur in dev environment, but only when you run:

next build
next start

and in prod when you acces for the first time, to test, you can open some private windows and try access the site: https://morethan-log.vercel.app/apollo-gettings-started-mutate sometimes

Debug approach

First stuff I done was removing the prismjs imports in the notion renderer components to understand if it would work without them. So, they worked and I discovered the origin of the problem.

After this I was thinking for some days about could be happening and decided to try import the highlights out of the promise, I was thinking that the amount of JS files being loaded could be making the highlight lazy since when I was debugging the code appear first without highlight and right after in next breakpoint it disappear.

Solution

So I moved the imports to the root layout, installed prismjs (I previously checked it it was in the package.json and it wasn't there) and imported it according some internet tutorials.

After all, I used prism to code:

  useEffect(() => {
    Prism.highlightAll();
  }, []);

And doing this, It was working all time, so if you can test and assure it, I would be very grateful.

Related tickets

#309

PR Checklist

adding prismjs to declared modules since it will be
imported to solve the problem of code blocks loading
root layout

adding language highlight imports to the
root layout and starting the highlight from useEffect,
it wil make the prism enable the highlight in the
code blocks
I removed this because seems to me it is taking too
much time to load all the components in the promise
and not loading the highlight over the code block
Copy link

vercel bot commented Jan 20, 2024

Someone is attempting to deploy a commit to a Personal Account owned by @morethanmin on Vercel.

@morethanmin first needs to authorize it.

@EddieSCJ
Copy link
Contributor Author

@morethanmin

Copy link

vercel bot commented Jan 26, 2024

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

Name Status Preview Comments Updated (UTC)
morethan-log ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 26, 2024 4:36pm

Copy link
Owner

@morethanmin morethanmin left a comment

Choose a reason for hiding this comment

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

I apologize for being late. Thank you for your patience!

@morethanmin morethanmin merged commit 42963be into morethanmin:main Jan 26, 2024
2 checks passed
@EddieSCJ
Copy link
Contributor Author

I apologize for being late. Thank you for your patience!

No worries.

Its me who need to thank you for creating this template.

@EddieSCJ EddieSCJ deleted the fix/issue-301-code-blocks-not-loading-all-the-time branch January 27, 2024 05:05
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.

2 participants