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

Prevent Cloudflare Rocket Loader deferring script #156

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

andreacassani
Copy link

When using Cloudflare with Rocket Loader enabled, the script injected by next-themes gets deferred causing the screen to flash.

As per Cloudflare docs, adding data-cfasync="false" to the <script /> tag prevents this behavior from happening, and the flash doesn't happen anymore.

I don't know if this is the best solution, but since Cloudflare is quite common and Rocket Loader is enabled by default, this might be useful for people who want to keep it enabled or for those who don't actually know it will prevent next-themes from working properly.

@vercel
Copy link

vercel bot commented Nov 25, 2022

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

Name Status Preview Comments Updated
next-themes-basic ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Nov 25, 2022 at 7:26PM (UTC)
next-themes-tailwind ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Nov 25, 2022 at 7:26PM (UTC)

@pacocoursey
Copy link
Owner

Not a fan of adding this universally – not everyone uses CloudFlare. But it would be better to support spreading props onto the <script /> tag so you can just add it yourself.

@andreacassani
Copy link
Author

Not a fan of adding this universally – not everyone uses CloudFlare. But it would be better to support spreading props onto the <script /> tag so you can just add it yourself.

Yes, you are totally right. I've added a new prop scriptAttribute to the ThemeProvider where we can pass attributes and their values down to the <script /> element. I've also updated the readme with an example. Let me know what do you think

@nicholashamilton
Copy link

nicholashamilton commented Jan 3, 2023

@andreacassani I've temporarily disabled Rocket Loader on my site because of the flash on page load.
I would find it useful if they merged this PR to allow scriptAttribute on the next-themes ThemeProvider.

@alakhpc
Copy link

alakhpc commented Jun 24, 2023

is there something blocking this? I believe this would be very useful.

@dollannn
Copy link

What is the status for this? What is blocking, are we looking for alternative solutions?

@patelvivekdev
Copy link

patelvivekdev commented May 5, 2024

Thank you

Solved: #281 (comment)

If there is no alternative, I think this PR should be merge.
@pacocoursey

@trm217 trm217 requested a review from pacocoursey May 9, 2024 15:14
Copy link
Collaborator

@trm217 trm217 left a comment

Choose a reason for hiding this comment

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

looks good to me, but I'd like @pacocoursey to sign off on it

@trm217 trm217 added the enhancement New feature or request label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants