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

React-compiler not working with 'module:@preact/signals-react-transform' #652

Open
3 of 5 tasks
mendrik opened this issue Feb 1, 2025 · 2 comments
Open
3 of 5 tasks
Labels

Comments

@mendrik
Copy link

mendrik commented Feb 1, 2025

  • Check if updating to the latest version resolves the issue

Environment

  • I am using @preact/signals-core
  • I am using @preact/signals
  • I am using @preact/signals-react
  • I understand usage changed in v2, and I've followed the React Integration instructions

Describe the bug

plugins: [
		tsconfigPaths(),
		react({
			babel: {
				plugins: [
					['module:@preact/signals-react-transform'],
					['babel-plugin-react-compiler', { transform: 'preact' }]
				]
			}
		})
	] as ViteUserConfig['plugins'],

To Reproduce
React compiler and @preact/signals-react-transform don't play nice together. It doesn't matter in which order they are added to vite config.

Steps to reproduce the behavior:

It seems like there is no reactivity: changes to values in signals don't re-render the component any longer

Expected behavior
Well I would expect them to be disjunct in their functionalities. But it seems one breaks the other.

@rschristian
Copy link
Member

rschristian commented Feb 1, 2025

Please provide a reproduction as our issue template requires.

What is { transform: 'preact' } meant to do in the config?

Edit: This seems to work.

// app.jsx
import { useSignal } from '@preact/signals-react';

function App() {
    const count = useSignal(0);

    return (
        <button onClick={() => count.value++}>
          count is {count.value % 2 == 0 ? 'even' : 'odd'}
        </button>
    );
}
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vite.dev/config/
export default defineConfig({
    plugins: [
        react({
            babel: {
                plugins: [
                    ['module:@preact/signals-react-transform'],
                    ['babel-plugin-react-compiler']
                ]
            }
        })
    ],
});

Hence why repos are required.

@mendrik
Copy link
Author

mendrik commented Feb 13, 2025

Ok I will try to make a repo, I use static signals outside of my components though, so maybe that makes the difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants