Skip to content

fix(shared): Force disable swr devtools for organization hooks #1694

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

Merged
merged 2 commits into from
Sep 13, 2023

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Sep 7, 2023

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/types
  • @clerk/themes
  • @clerk/localizations
  • @clerk/clerk-expo
  • @clerk/backend
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/fastify
  • @clerk/chrome-extension
  • gatsby-plugin-clerk
  • build/tooling/chore

Description

  • npm test runs as expected.
  • npm run build runs as expected.

This PR fixes a bug where the application would break if the SWR Devtools extention was enabled in the broswer.

See 👉 SWR Devtool Issue

By overriding the window.SWR_DEVTOOLS_USE with a false value before importing swr, enables us to disable swr from "hinting" to swr-devtools which react version to use.

Clerk Dashboard

Before

Screen.Recording.2023-09-07.at.8.40.55.PM.mov

After

Screen.Recording.2023-09-07.at.8.41.26.PM.mov

@changeset-bot
Copy link

changeset-bot bot commented Sep 7, 2023

🦋 Changeset detected

Latest commit: a71f6bb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@clerk/shared Patch
@clerk/clerk-js Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
gatsby-plugin-clerk Patch
@clerk/nextjs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@panteliselef
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @panteliselef - the snapshot version command generated the following package versions:

Package Version
@clerk/chrome-extension 0.3.32-snapshot.965d3c8
@clerk/clerk-js 4.57.1-snapshot.965d3c8
@clerk/clerk-expo 0.19.2-snapshot.965d3c8
gatsby-plugin-clerk 4.4.8-snapshot.965d3c8
@clerk/nextjs 4.23.6-snapshot.965d3c8
@clerk/clerk-react 4.24.3-snapshot.965d3c8
@clerk/remix 2.10.3-snapshot.965d3c8
@clerk/shared 0.22.1-snapshot.965d3c8

Tip: use the snippet copy button below to quickly install the required packages.

# @clerk/chrome-extension
npm i @clerk/[email protected]
# @clerk/clerk-js
npm i @clerk/[email protected]
# @clerk/clerk-expo
npm i @clerk/[email protected]
# gatsby-plugin-clerk
npm i [email protected]
# @clerk/nextjs
npm i @clerk/[email protected]
# @clerk/clerk-react
npm i @clerk/[email protected]
# @clerk/remix
npm i @clerk/[email protected]
# @clerk/shared
npm i @clerk/[email protected]

@panteliselef panteliselef changed the title [WIP] fix(shared): Force disable swr devtools for organization hooks fix(shared): Force disable swr devtools for organization hooks Sep 7, 2023
Copy link
Member

@nikosdouvlis nikosdouvlis left a comment

Choose a reason for hiding this comment

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

Good job tracking this one down @panteliselef :)


import { disableSWRDevtools } from './clerk-swr';
disableSWRDevtools();
Copy link
Member

Choose a reason for hiding this comment

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

Given that this is a top-level side effect already, I think we can simply call it inside once inside clerk-swr.ts directly.

If we wanted to avoid top-level side-effects altogether, an alternative approach would be to create our own SWR wrapper and call disableSWRDevtools internally, eg:

import { useSWR as _useSWR } from 'swr';
export useSWR = () => {
    disableSWRDevtools();
    return _useSWR;
}

No real preference here :)

Copy link
Member Author

Choose a reason for hiding this comment

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

We tried this, but was not working.

// file: clerk-swr.ts
  if (typeof window !== 'undefined') {
    // @ts-ignore
    window.__SWR_DEVTOOLS_USE__ = undefined;
  }


export * from 'swr';
export { default as useSWR } from 'swr';
export { default as useSWRInfinite } from 'swr/infinite';

Also swr setups the devtools once imported not once the hooks is called. Do you think your recommendation would still work with that in mind ?

@panteliselef panteliselef force-pushed the ORG-201 branch 2 times, most recently from b000370 to 8787c05 Compare September 12, 2023 13:04
@clerk-cookie
Copy link
Collaborator

This PR has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@clerk clerk locked as resolved and limited conversation to collaborators Sep 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants