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

Components not rendering. #261

Open
daviddanielng opened this issue Feb 18, 2025 · 8 comments
Open

Components not rendering. #261

daviddanielng opened this issue Feb 18, 2025 · 8 comments
Assignees

Comments

@daviddanielng
Copy link

I want to try react scan, it is not working as expected.

The website will show a blank screen and react-scan toggle when i add the script tag, the page will be render when i remove the script tag.

I am using react and vite.
React: 19.0.0
Vite: 6.0.11

When react scan is enabled
Image

when react scan is disabled

Image

And the instruction for vite installation in the dashboard has an error Cannot find name 'usePathname'. Did you mean 'pathname'?ts(2552)

@pivanov
Copy link
Collaborator

pivanov commented Feb 18, 2025

Hey @daviddanielng
Can you show your vite config? or the way you load react-scan?

@pivanov pivanov self-assigned this Feb 18, 2025
@daviddanielng
Copy link
Author

Hey @daviddanielng Can you show your vite config? or the way you load react-scan?

Just the script tag.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Meta School Info Admin</title>
    <meta charset="UTF-8" />
    <link
      rel="icon"
      type="image/svg+xml"
      href="/icons/admin-favicon.svg"
      sizes="150x150"
    />
    <link
      rel="apple-touch-icon"
      sizes="512x512"
      href="/images/admin-app-icon.png"
    />
    <meta name="apple-mobile-web-app-title" content="Meta School Info Admin" />
    <link rel="manifest" href="/admin.webmanifest" />

    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://api.metaschoolinfo.me" />
    <link rel="preconnect" href="https://www.googletagmanager.com" />
   <script
      crossOrigin="anonymous"
      src="//unpkg.com/react-scan/dist/auto.global.js"
    />

    <meta name="robots" content="noindex" />
    <meta
      rel="preload"
      href="https://fonts.googleapis.com/css2?family=Fredoka&display=swap"
    />
    <meta
      name="theme-color"
      media="(prefers-color-scheme: light)"
      content="#53574f"
    />
    <meta
      name="theme-color"
      media="(prefers-color-scheme: dark)"
      content="#1a1a1b"
    />
  </head>
  <body>
    <div id="admin-root"></div>

    <script type="module" src="/src/adminapp.tsx"></script>
  </body>
</html>

vite.config.js

import { sentryVitePlugin } from "@sentry/vite-plugin";
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import dns from "node:dns";
import { resolve } from "path";
import { defineConfig, loadEnv } from "vite";

dns.setDefaultResultOrder("verbatim");

const ReactCompilerConfig = {
  /* ... */
};

export default defineConfig(({ mode }) => {
  // Load environment variables based on the current mode (development, production, etc.)
  const env = loadEnv(mode, process.cwd());

  return {
    base: "/",
    plugins: [
      react({
        babel: {
          plugins: [["babel-plugin-react-compiler", ReactCompilerConfig]],
        },
      }),
      tailwindcss(),

      sentryVitePlugin({
        authToken: env.SENTRY_AUTH_TOKEN,
        org: "cloudy-curtain",
        project: "meta-school-info",
        telemetry: false,
      }),
    ],
    build: {
      sourcemap: false,
      rollupOptions: {
        input: {
          main: resolve(__dirname, "index.html"),
          admin: resolve(__dirname, "admin.html"),
        },
      },
    },
    server: {
      host: true,
      port: Number(env.VITE_PORT),
      strictPort: true,
      headers: {
        "Cross-Origin-Opener-Policy": "same-origin-allows-popups",
      },
      allowedHosts: ["e0b2-172-166-156-161.ngrok-free.app"],
      proxy: {
        "/api": {
          target: "http://localhost:9060",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
  };
});

I did set it up with vite, it did not work so i removed it.

@pivanov
Copy link
Collaborator

pivanov commented Feb 18, 2025

Hm ... strange.
Here is a vite example (https://github.com/react-scan/react-scan-vite-example)
If your project is public I can jump in to see what's going on?

@daviddanielng
Copy link
Author

Hm ... strange. Here is a vite example (https://github.com/react-scan/react-scan-vite-example) If your project is public I can jump in to see what's going on?

Unfortunately, the project is private I was brought in when one of the devs was fired for neglect.

One of devs said the project was created with npm create vite@latest project -- --template react-swc-ts, the initial config looked like (https://github.com/react-scan/react-scan-vite-example/blob/main/vite.config.ts) then some additional config was added.

I could tag one of them, but none of them cares about the project.

@pivanov
Copy link
Collaborator

pivanov commented Feb 18, 2025

No worries ... can you try the setup from the https://github.com/react-scan/react-scan-vite-example?
you just need to install these:

npm install -D @react-scan/vite-plugin-react-scan react-scan

then in you vite config

plugins: [
    ...
    reactScan(),
    ...
],

If this works (should works) you can check the Options to make any adjustments if you want

@daviddanielng
Copy link
Author

If this works (should works) you can check the Options to make any adjustments if you want

This triggered an error when used with tailwind CSS.

It is tailwind version 4.

Image

@pivanov
Copy link
Collaborator

pivanov commented Feb 18, 2025

so it works without react-scan? but with react-scan you see this tailwind error?
Are you able to make a demo project with most of your setup and with react-scan and share the repo? It will be very helpful!

@daviddanielng
Copy link
Author

so it works without react-scan? but with react-scan you see this tailwind error? Are you able to make a demo project with most of your setup and with react-scan and share the repo? It will be very helpful!

I will do that.

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

No branches or pull requests

2 participants