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

Wrap jsxDEV which export from react/jsx-dev-runtime #6517

Closed
7 tasks done
wqcstrong opened this issue Jan 15, 2022 · 1 comment
Closed
7 tasks done

Wrap jsxDEV which export from react/jsx-dev-runtime #6517

wqcstrong opened this issue Jan 15, 2022 · 1 comment

Comments

@wqcstrong
Copy link

wqcstrong commented Jan 15, 2022

Describe the bug

Background

i18n in my react project is implmented by wrap jsxDEV which is export from react/jsx-dev-runtime, just like interceptor before render.

What happened?

The translate behavior is not expected in serve mode and unexpected result after vite build.

After checking, the more specified detail is there would be two copies of react/jsx-dev-runtime:

  1. @vitejs/plugin-react use one;
  2. other one imported by myself;

What the unexpected behavior is the 1st one would compile after vite serve, and the 2nd would excute if I trigger hot update behavior, for example, save file.

The expected behavior

The @vitejs/plugin-react is powerful, but what should I do to adapt in my case.

Reproduction

https://github.com/wqcstrong/vite-issues

System Info

System:
    OS: macOS 12.0.1
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 1.02 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Firefox: 95.0.2
    Safari: 15.1
  npmPackages:
    @vitejs/plugin-react: ^1.0.7 => 1.1.4 
    vite: ^2.7.2 => 2.7.12

Used Package Manager

yarn

Logs

No response

Validations

@wqcstrong
Copy link
Author

wqcstrong commented Jan 18, 2022

Just in above case someone else wanted to get some advice.

Since I don't get any response or comments, as compromise, I adjusted the implementation... give up modify react's "render" methods except for React.createElement.

Following is the config:

// vite.config.ts
import react from '@vitejs/plugin-react'
import { viteExternalsPlugin as externals } from 'vite-plugin-externals';

export default defineConfig({
  ...,
  esbuild: {
    jsxFactory: "React.createElemennt",
    jsxFragment: "React.Fragment"
  },
  plugins: [
    react({
      jsxRuntime: "classic"
    }),
    externals({
      react: 'window.React',
      'react-dom': 'window.ReactDOM'
    },{ useWindow: false })
  ]
})

and remove the jsxDev interceptor in the business code.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants