Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/solid-hook-naming-react-compiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@tanstack/devtools-ui': minor
'@tanstack/devtools': patch
'@tanstack/devtools-a11y': patch
---

fix: rename Solid `use*` primitives to `create*` so React Compiler doesn't transform them

The devtools packages are written in Solid but used React-style naming (`useStyles`, `useTheme`, `useDevtoolsState`, …) for their custom primitives. When an app enables React Compiler, the compiler matches the `use*` naming convention and transforms/optimizes this Solid code as if it were React, breaking the panel (it is Solid JSX, not React).

All custom Solid primitives in `@tanstack/devtools`, `@tanstack/devtools-ui`, and `@tanstack/devtools-a11y` are renamed from `use*` to `create*`, and Solid's own `useContext` / `@solid-primitives` `useKeyDownList` are imported under non-`use` aliases (`getContext`, `getKeyDownList`).

Breaking for `@tanstack/devtools-ui`: the exported `useTheme` is renamed to `createTheme`.
4 changes: 2 additions & 2 deletions packages/devtools-a11y/src/core/components/IssueCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { For, Show } from 'solid-js'
import { Button } from '@tanstack/devtools-ui'
import { useStyles } from '../styles/styles'
import { createStyles } from '../styles/styles'

// types
import type { A11yIssue, SeverityThreshold } from '../types/types'
Expand All @@ -17,7 +17,7 @@ interface A11yIssueCardProps {

export function A11yIssueCard(props: A11yIssueCardProps) {
const selector = () => props.issue.nodes[0]?.selector || 'unknown'
const styles = useStyles()
const styles = createStyles()

return (
<div
Expand Down
8 changes: 4 additions & 4 deletions packages/devtools-a11y/src/core/components/IssueList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsxImportSource solid-js */

import { For, Show } from 'solid-js'
import { useAllyContext } from '../contexts/allyContext'
import { createAllyContext } from '../contexts/allyContext'
import {
SEVERITY_LABELS,
clearHighlights,
Expand All @@ -10,7 +10,7 @@ import {
scrollToElement,
} from '../utils/ui.utils'
import { IMPACTS } from '../utils/ally-audit.utils'
import { useStyles } from '../styles/styles'
import { createStyles } from '../styles/styles'
import { A11yIssueCard } from './IssueCard'

// types
Expand All @@ -24,8 +24,8 @@ export function A11yIssueList(props: A11yIssueListProps) {
const [selectedIssueId, setSelectedIssueId] = props.selectedIssueSignal

// hooks
const styles = useStyles()
const ally = useAllyContext()
const styles = createStyles()
const ally = createAllyContext()

// handlers
const handleIssueClick = (issueId: string) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/devtools-a11y/src/core/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { For, Show, createMemo, createSignal } from 'solid-js'
import { Button, Input, Select } from '@tanstack/devtools-ui'
import { getAvailableRules } from '../utils/ally-audit.utils'
import { useAllyContext } from '../contexts/allyContext'
import { CATEGORIES, CATEGORY_LABELS, useStyles } from '../styles/styles'
import { createAllyContext } from '../contexts/allyContext'
import { CATEGORIES, CATEGORY_LABELS, createStyles } from '../styles/styles'

// types
import type {
Expand All @@ -18,8 +18,8 @@ interface A11ySettingsOverlayProps {
}

export function A11ySettingsOverlay(props: A11ySettingsOverlayProps) {
const { config, setConfig } = useAllyContext()
const styles = useStyles()
const { config, setConfig } = createAllyContext()
const styles = createStyles()

const disabledRulesSet = createMemo(() => new Set(config.disabledRules))
const availableRules = createMemo(() => getAvailableRules())
Expand Down
8 changes: 4 additions & 4 deletions packages/devtools-a11y/src/core/components/Shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import { Match, Show, Switch, createMemo, createSignal } from 'solid-js'
import { Button, Header, MainPanel } from '@tanstack/devtools-ui'
import { useAllyContext } from '../contexts/allyContext'
import { createAllyContext } from '../contexts/allyContext'
import { RULE_SET_LABELS, SEVERITY_LABELS } from '../utils/ui.utils'
import { useStyles } from '../styles/styles'
import { createStyles } from '../styles/styles'
import { A11yIssueList } from './IssueList'
import { A11ySettingsOverlay } from './Settings'

export function Shell() {
const styles = useStyles()
const styles = createStyles()

// ally context
const { filteredIssues, allyResult, config, setConfig, triggerAllyScan } =
useAllyContext()
createAllyContext()

// ui state
const selectedIssueSignal = createSignal<string>('')
Expand Down
14 changes: 7 additions & 7 deletions packages/devtools-a11y/src/core/contexts/allyContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createEffect,
createMemo,
createSignal,
useContext,
useContext as getContext,
} from 'solid-js'
import { createStore } from 'solid-js/store'
import { filterIssuesAboveThreshold, runAudit } from '../utils/ally-audit.utils'
Expand All @@ -24,7 +24,7 @@ import type { ParentComponent } from 'solid-js'
// context state
//

function useAllyValue() {
function createAllyValue() {
const [config, setConfig] =
createStore<Required<A11yPluginOptions>>(mergeConfig())

Expand Down Expand Up @@ -89,7 +89,7 @@ function useAllyValue() {
}
}

type ContextType = ReturnType<typeof useAllyValue>
type ContextType = ReturnType<typeof createAllyValue>

//
// context
Expand All @@ -100,18 +100,18 @@ const AllyContext = createContext<ContextType | null>(null)
type AllyProviderProps = {}

export const AllyProvider: ParentComponent<AllyProviderProps> = (props) => {
const value = useAllyValue()
const value = createAllyValue()

return (
<AllyContext.Provider value={value}>{props.children}</AllyContext.Provider>
)
}

export function useAllyContext() {
const context = useContext(AllyContext)
export function createAllyContext() {
const context = getContext(AllyContext)

if (context === null) {
throw new Error('useAllyContext must be used within an AllyProvider')
throw new Error('createAllyContext must be used within an AllyProvider')
}

return context
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools-a11y/src/core/styles/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as goober from 'goober'
import { useTheme } from '@tanstack/devtools-ui'
import { createTheme } from '@tanstack/devtools-ui'
import { createMemo } from 'solid-js'

import type { TanStackDevtoolsTheme } from '@tanstack/devtools-ui'
Expand Down Expand Up @@ -548,8 +548,8 @@ function createA11yPanelStyles(theme: TanStackDevtoolsTheme) {
}
}

export function useStyles() {
const { theme } = useTheme()
export function createStyles() {
const { theme } = createTheme()
const styles = createMemo(() => createA11yPanelStyles(theme()))

return styles
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ui/src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMemo } from 'solid-js'
import clsx from 'clsx'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'

// types
import type { JSX } from 'solid-js'
Expand All @@ -20,7 +20,7 @@ type ButtonProps = JSX.ButtonHTMLAttributes<HTMLButtonElement> & {
className?: string
}
export function Button(props: ButtonProps) {
const styles = useStyles()
const styles = createStyles()

const classes = createMemo(() => {
const variant = props.variant || 'primary'
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ui/src/components/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal } from 'solid-js'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'

interface CheckboxProps {
label?: string
Expand All @@ -9,7 +9,7 @@ interface CheckboxProps {
}

export function Checkbox(props: CheckboxProps) {
const styles = useStyles()
const styles = createStyles()
const [isChecked, setIsChecked] = createSignal(props.checked || false)

const handleChange = (e: Event) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools-ui/src/components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import clsx from 'clsx'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'
import type { JSX } from 'solid-js/jsx-runtime'

export function Header({
children,
class: className,
...rest
}: JSX.IntrinsicElements['header']) {
const styles = useStyles()
const styles = createStyles()
return (
<header
class={clsx(styles().header.row, 'tsqd-header', className)}
Expand All @@ -30,7 +30,7 @@ export function HeaderLogo({
}
onClick?: JSX.EventHandler<HTMLButtonElement, MouseEvent>
}) {
const styles = useStyles()
const styles = createStyles()
return (
<div class={styles().header.logoAndToggleContainer}>
<button class={clsx(styles().header.logo)} onClick={onClick}>
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ui/src/components/input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal } from 'solid-js'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'

interface InputProps {
label?: string
Expand All @@ -11,7 +11,7 @@ interface InputProps {
}

export function Input(props: InputProps) {
const styles = useStyles()
const styles = createStyles()
const [val, setVal] = createSignal(props.value || '')

const handleChange = (e: Event) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ui/src/components/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createUniqueId } from 'solid-js'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'

export function TanStackLogo() {
const id = createUniqueId()
const styles = useStyles()
const styles = createStyles()
return (
<svg
class={styles().logo}
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ui/src/components/main-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'
import type { JSX } from 'solid-js/jsx-runtime'

type PanelProps = JSX.IntrinsicElements['div'] & {
Expand All @@ -14,7 +14,7 @@ export const MainPanel = ({
class: classStyles,
withPadding,
}: PanelProps) => {
const styles = useStyles()
const styles = createStyles()

return (
<div
Expand Down
10 changes: 5 additions & 5 deletions packages/devtools-ui/src/components/section.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import clsx from 'clsx'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'
import type { JSX } from 'solid-js/jsx-runtime'

export const Section = ({
children,
...rest
}: JSX.IntrinsicElements['section']) => {
const styles = useStyles()
const styles = createStyles()
return (
<section class={clsx(styles().section.main, rest.class)} {...rest}>
{children}
Expand All @@ -18,7 +18,7 @@ export const SectionTitle = ({
children,
...rest
}: JSX.IntrinsicElements['h3']) => {
const styles = useStyles()
const styles = createStyles()
return (
<h3 class={clsx(styles().section.title, rest.class)} {...rest}>
{children}
Expand All @@ -30,7 +30,7 @@ export const SectionDescription = ({
children,
...rest
}: JSX.IntrinsicElements['p']) => {
const styles = useStyles()
const styles = createStyles()
return (
<p class={clsx(styles().section.description, rest.class)} {...rest}>
{children}
Expand All @@ -42,7 +42,7 @@ export const SectionIcon = ({
children,
...rest
}: JSX.IntrinsicElements['span']) => {
const styles = useStyles()
const styles = createStyles()
return (
<span class={clsx(styles().section.icon, rest.class)} {...rest}>
{children}
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ui/src/components/select.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal } from 'solid-js'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'

interface SelectOption<T extends string | number> {
value: T
Expand All @@ -15,7 +15,7 @@ interface SelectProps<T extends string | number> {
}

export function Select<T extends string | number>(props: SelectProps<T>) {
const styles = useStyles()
const styles = createStyles()
const [selected, setSelected] = createSignal(
props.value || props.options[0]?.value,
)
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-ui/src/components/tag.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Show } from 'solid-js'
import { useStyles } from '../styles/use-styles'
import { createStyles } from '../styles/use-styles'
import type { tokens } from '../styles/tokens'

export const Tag = (props: {
Expand All @@ -8,7 +8,7 @@ export const Tag = (props: {
count?: number
disabled?: boolean
}) => {
const styles = useStyles()
const styles = createStyles()
return (
<button disabled={props.disabled} class={styles().tag.base}>
<span class={styles().tag.dot(props.color)} />
Expand Down
13 changes: 9 additions & 4 deletions packages/devtools-ui/src/components/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { createContext, createEffect, createSignal, useContext } from 'solid-js'
import {
createContext,
createEffect,
createSignal,
useContext as getContext,
} from 'solid-js'
import type { Accessor, JSX } from 'solid-js'

export type TanStackDevtoolsTheme = 'light' | 'dark'
Expand All @@ -24,10 +29,10 @@ export const ThemeContextProvider = (props: {
)
}

export function useTheme() {
const context = useContext(ThemeContext)
export function createTheme() {
const context = getContext(ThemeContext)
if (!context) {
throw new Error('useTheme must be used within a ThemeContextProvider')
throw new Error('createTheme must be used within a ThemeContextProvider')
}

return context
Expand Down
Loading
Loading