Global component failed to work

I was using the following code to get user location based on their permission by clicking on button. It was working in my other project but failed to work on my new project.

import React, { useState } from "react";
import {
  DataProvider,
  GlobalActionsProvider,
} from "@plasmicapp/react-web/lib/host";

type Location = {
  latitude: number | null;
  longitude: number | null;
};

export function UserLocation({ children }: { children: React.ReactNode }) {
  const [permission, setPermission] = useState(false);
  const [location, setLocation] = useState<Location>({
    latitude: null,
    longitude: null,
  });

  const fetchLocation = () => {
    if (typeof window === "undefined") return;

    if (!navigator?.geolocation) {
      console.warn("Geolocation not supported");
      return;
    }

    navigator.geolocation.getCurrentPosition(
      (pos) => {
        console.log("✅ Got location:", pos.coords);
        setLocation({
          latitude: pos.coords.latitude,
          longitude: pos.coords.longitude,
        });
        setPermission(true);
      },
      (err) => {
        console.error("❌ Geolocation error:", err);
        setPermission(false);
      }
    );
  };

  return (
    <GlobalActionsProvider
      contextName="UserLocation"
      actions={{ requestPermission: fetchLocation }}
    >
      <DataProvider
        name="userLocation"
        data={{
          latitude: location.latitude,
          longitude: location.longitude,
          permission,
        }}
      >
        {children}
      </DataProvider>
    </GlobalActionsProvider>
  );
}

This the component registration in plasmic-host

registerGlobalContext(UserLocation, {
  // name should match GlobalActionsProvider contextName
  name: "UserLocation",
  // props should match LocationProviderProps
  props: {},
  // providesData should be true if the global context has a DataProvider
  providesData: true,
  // globalActions should match the global context's GlobalActionsProvider
  globalActions: {
    requestPermission: {
      displayName: "Request Location",
      parameters: [],
    },
  },
   importPath: './components/UserLocation',
});

Further if $ctx is included in text component, the component will only be visible in plasmic studio and not at localhost

"User Location: " + $ctx.userLocation.permission

Plasmic Studio screenshot. Note the different on “User Location: false”

localhost screenshot:

I also notice following embedded CSS is not working

/* CSS snippet */

.shimmer-box {
  background: linear-gradient(
    90deg,
    #2e4383 0%,   /* darker shade */
    #3953A4 70%,  /* base blue */
    #4a67c8 100%  /* lighter shade */
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
}


@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

My project ID: 8sZCTFVobhhvVTD2aCPAs5

I had tried to create using html to detect user location and it worked.

Hope for some enlightment.

Thank you.

Hello @mouthains, I did a codegen of your project - I can see that the global action is correctly being called, so it seems like the issue is not related to Plasmic. Also, I can see the text in both Studio and browser.

I can also see that the embed css is correctly applied on the elements with class name shimmer-box

I had done several troubleshooting but same problems persist.

All these while I was using npx create-plasmic-app to create new project which will installed the latest NextJs version. Following is the package.json after downgrade to prior version that I was able to use the UserLocation

{
  "name": "chapter1",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev --turbopack",
    "build": "next build --turbopack",
    "start": "next start",
    "lint": "eslint"
  },
  "dependencies": {
    "@next/third-parties": "15.5.3",
    "@plasmicapp/cli": "^0.1.345",
    "@plasmicapp/react-web": "^0.2.403",
    "@plasmicpkgs/plasmic-basic-components": "^0.0.255",
    "@plasmicpkgs/plasmic-embed-css": "^0.1.212",
    "next": "15.5.3",
    "react": "^19.2.0",
    "react-dom": "^19.2.0"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3",
    "@types/node": "^24.6.1",
    "@types/react": "^19.2.0",
    "@types/react-dom": "^19.2.0",
    "eslint": "^9",
    "eslint-config-next": "15.5.3",
    "typescript": "^5"
  },
  "overrides": {
    "next": "15.5.3"
  }
}

I even tried using npx create-plasmic-app@latest to create new project which installed NextJs version 14. But same problem persists. Below is the package.json

{
  "name": "chapter4",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@plasmicapp/cli": "^0.1.345",
    "@plasmicapp/react-web": "^0.2.403",
    "next": "14.2.33",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.33",
    "typescript": "^5"
  }
}

Following is the package.json of existing project that I can use the UserLocation component.

{
  "name": "chapter3",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev --turbopack",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@ant-design/icons": "^6.0.0",
    "@ant-design/pro-components": "^2.6.4",
    "@marsidev/react-turnstile": "^1.3.0",
    "@next/third-parties": "^15.4.6",
    "@plasmicapp/auth-api": "^0.0.17",
    "@plasmicapp/cli": "^0.1.342",
    "@plasmicapp/react-web": "^0.2.400",
    "@plasmicpkgs/antd5": "^0.0.301",
    "@plasmicpkgs/plasmic-basic-components": "^0.0.251",
    "@plasmicpkgs/plasmic-embed-css": "^0.1.211",
    "@plasmicpkgs/plasmic-query": "^0.0.243",
    "@plasmicpkgs/plasmic-rich-components": "^1.0.222",
    "@plasmicpkgs/react-aria": "^0.0.150",
    "@supabase/ssr": "^0.6.1",
    "@supabase/supabase-js": "^2.55.0",
    "next": "^15.4.6",
    "nodemailer": "^7.0.5",
    "react": "^19.1.1",
    "react-dom": "^19.1.1",
    "swr": "^2.3.6"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3",
    "@types/node": "^24.3.0",
    "@types/nodemailer": "^7.0.0",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "eslint": "^9",
    "eslint-config-next": "15.4.6",
    "typescript": "^5"
  }
}

Looking forward to some enlightment.

Thank you.