javascript: Changing a localization in ClerkProvider causes an error "Failed to execute 'removeChild' on 'Node'"

Package + Version

  • @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
  • other:

Dependencies + versions

Provide a json with the dependencies used in your project (copy paste from yarn.lock / package-lock.json) or a github project / template that reproduces the issue.

Include the @clerk/ packages and their versions!*

Example:

  "dependencies": {
    "@clerk/localizations": "^1.24.1",
    "@clerk/nextjs": "^4.23.2",
    "@types/node": "20.4.5",
    "@types/react": "18.2.18",
    "@types/react-dom": "18.2.7",
    "next": "^13.4.12",
    "next-intl": "3.0.0-beta.9",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "typescript": "5.1.6",
  },
  "devDependencies": {
    "@clerk/types": "^3.49.0",
  }

Description

I am using Clerk + next-intl + next.js app router to handle localizations. I have a language switcher which changes an URL from /en to /dk (using router.replace). This updates const locale = useLocale(); within the root layout, as seen in the code below.

import { ClerkProvider } from "@clerk/nextjs";
import { useLocale } from "next-intl";

import { daDK, enUS } from "@clerk/localizations";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const locale = useLocale();

  return (
    <ClerkProvider localization={locale === "dk" ? daDK : enUS}>
      {children}
    </ClerkProvider>
  );
}

Once the locale has changed and the new value is passed into ClerkProvider all the clerk elements disappear from the screen and throw an error

DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
    at https://xxxx-xxxx.clerk.accounts.dev

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 17 (9 by maintainers)

Most upvoted comments

This problem still exists in the latest version @clerk/nextjs@4.27.6

Hey @LekoArts , sorry for the wrong reproduction repo. I have updated it with missing pages. Tested it again and it is still reproducible for me. The steps were:

  1. Open a page in incognito mode
  2. Login using Gmail provider
  3. Click “Dansk” to change a language
  4. Confirm that the UserButton is missing
  5. Hard refresh the page, and confirm that UserButton is now present.

I also noticed that console complains about the authMiddleware, image

Hello @namdien177 and sorry for the late response. We have marked this issue for internal triage.

Issues that have the label needs-triage have been seen by our team and are queued for triage internally ref: https://github.com/clerkinc/javascript/blob/d684e6f1f7913350bab0d9fb2424ca783b5a7993/docs/CONTRIBUTING.md?plain=1#L147