-
|
Hi! I'm trying to use react-strict-dom with Vite (and TanStack Start, to be precise). I've seen multiple issues on this topic, but none of them solve the problem: Related issues: I'm getting the same error as in those issues:
Has anyone managed to get this working? Thanks! CODE : vite.config.ts: import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import tsConfigPaths from 'vite-tsconfig-paths'
import babel from "vite-plugin-babel";
import path from 'path';
export default defineConfig(() => ({
server: {
port: 3000
},
plugins: [
tsConfigPaths(),
tanstackStart(),
react({
babel: {
configFile: path.resolve(__dirname, 'babel.config.cjs')
}
}),
babel({
include: /node_modules\/react-strict-dom(-svg)?/
})
],
}));postcss.config.js: export default {
plugins: {
"postcss-react-strict-dom": {
include: [
"node_modules/react-strict-dom/dist/dom/runtime.js",
"src/**/*.{js,jsx,ts,tsx}"
],
},
autoprefixer: {},
},
};babel.config.cjs: module.exports = {
presets: [
['@babel/preset-react', { runtime: 'automatic' }],
'react-strict-dom/babel-preset'
]
};global.css: @react-strict-dom; |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
Here is my setup with tanstack start / Vite & storybook vite.config.js import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import viteReact from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig({
server: {
port: 3447,
},
plugins: [
tsconfigPaths(),
tanstackStart({
srcDirectory: ".",
router: {
routesDirectory: "routes",
},
}),
// react's vite plugin must come after start's vite plugin
viteReact({
babel: { configFile: true },
exclude: [/\/node_modules\/(?!react-strict-dom)/],
}),
],
ssr: {
noExternal: ["react-strict-dom"],
},
optimizeDeps: {
exclude: ["react-strict-dom"],
},
});babelconfig.js const dev = process.env.NODE_ENV !== "production";
const config = {
parserOpts: {
plugins: ["typescript", "jsx"],
},
plugins: [
// Plugin to strip Vite's ?v=hash from filenames before react-strict-dom processes them
// otherwise we get react hydration mismatches due to different data-style-src values
function stripViteVersionFromFilename() {
return {
// Normalize filename by removing Vite's version query params
pre(file) {
if (file.opts.filename) {
file.opts.filename = file.opts.filename.split("?")[0];
}
},
};
},
],
presets: [
[
"react-strict-dom/babel-preset",
{
debug: dev,
dev,
platform: "web",
rootDir: process.cwd(),
},
],
],
};
export default config;postcss.config.mjs const config = {
plugins: {
"react-strict-dom/postcss-plugin": {
include: ["**/*.{js,jsx,ts,tsx}"],
useLayers: true,
},
},
};
export default config;.storybook/main.ts (rely on import { defineMain } from "@storybook/react-vite/node";
export default defineMain({
stories: [
"../@(app|components|styles|svgs)/**/*.mdx",
"../@(app|components|styles|svgs)/**/*.stories.@(js|jsx|mjs|ts|tsx)",
],
staticDirs: [
{ from: "../public/images", to: "images" },
{ from: "../public/fonts", to: "fonts" },
],
typescript: {
reactDocgen: "react-docgen-typescript",
},
addons: ["@storybook/addon-docs", "@storybook/addon-themes"],
framework: "@storybook/react-vite",
// vite config automatically merged in from vite.config.ts
}); |
Beta Was this translation helpful? Give feedback.
-
|
Here is my configuration, which works without errors (it’s a demo project, so there’s no advanced use of RSD / StyleX), but it might be useful for some people! NOTE: If you're experiencing a hydration issue, it might be caused by your Chrome extensions (see my previous comment)._ vite.config.ts: import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import tsConfigPaths from 'vite-tsconfig-paths'
import babel from "vite-plugin-babel";
export default defineConfig(() => ({
server: {
port: 3000
},
ssr: {
noExternal: ["react-strict-dom"],
},
plugins: [
tsConfigPaths(),
tanstackStart(),
react({
babel: {
configFile: true,
}
}),
babel(),
],
}));babel.config.js: const dev = process.env.NODE_ENV !== "production";
export default {
parserOpts: {
plugins: ["typescript", "jsx"],
},
plugins: [
// Plugin to strip Vite's ?v=hash from filenames before react-strict-dom processes them
// otherwise we get react hydration mismatches due to different data-style-src values
function stripViteVersionFromFilename() {
return {
// Normalize filename by removing Vite's version query params
pre(file) {
if (file.opts.filename) {
file.opts.filename = file.opts.filename.split("?")[0];
}
},
};
},
],
presets: [
[
'react-strict-dom/babel-preset',
{
debug: dev,
dev,
rootDir: process.cwd(),
platform: "web"
},
],
]
};postcss.config.js: export default {
plugins: {
"react-strict-dom/postcss-plugin": {
include: ["**/*.{js,jsx,ts,tsx}"],
useLayers: true,
},
},
};global.css: @react-strict-dom;__root.tsx: import appCss from '../global.css?url';
export const Route = createRootRoute({
head: () => ({
meta: [
{
charSet: 'utf-8',
},
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
{
title: 'TanStack Start Starter',
},
],
links: [{ rel: 'stylesheet', href: appCss }],
}),
component: RootComponent,
})package.json: {
"name": "tanstack-start-stylex-demo",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"start": "vite preview",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@tanstack/react-start": "^1.139.12",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-strict-dom": "^0.0.54",
"vite-plugin-babel": "^1.3.2"
},
"devDependencies": {
"@tanstack/router-plugin": "^1.139.14",
"@types/node": "^24.10.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^4.7.0",
"autoprefixer": "^10.4.22",
"typescript": "^5.9.3",
"vite": "^7.2.6",
"vite-tsconfig-paths": "^5.1.4"
}
} |
Beta Was this translation helpful? Give feedback.
Here is my configuration, which works without errors (it’s a demo project, so there’s no advanced use of RSD / StyleX), but it might be useful for some people!
NOTE: If you're experiencing a hydration issue, it might be caused by your Chrome extensions (see my previous comment)._
vite.config.ts: