developit / developit/htm

Hooks not working correctly using off-the-shelf htm@^3.1.0 and preact@^10.5.14

Abierto
#209 4 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
9k
Forks
181
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I am using htm and Preact as follows inside a simple functional component. This component is imported by a class component where it is swapped out according to a switching logic with another component. Here is how I am importing the libraries:

```js
import { html } from 'htm/preact';
import { useEffect, useRef, useState } from 'preact/hooks';
```

I have the latest installed versions of each package. Hooks appear to work fine on first mount, but when the component unmounts, any version of Preact past `10.2.0` is failing with the message `TypeError: Cannot read property '__hooks' of undefined`. If I install `10.2.0` explicitly then this error goes away. I assume it is because `htm` has this version in the devDependencies:

```json
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.1.6",
"@types/jest": "^26.0.24",
"babel-jest": "^24.1.0",
"babel-preset-env": "^1.7.0",
"eslint": "^5.2.0",
"eslint-config-developit": "^1.1.1",
"jest": "^24.1.0",
"microbundle": "^0.10.1",
"preact": "^10.2.0",
"react": "^16.8.3"
}
```

I think there is a version mismatch happening but I cannot figure out how to fix it. I tried module resolution but that didn't help. My `package.json` has these dependencies:

```json
"dependencies": {
"htm": "^3.1.0",
"preact": "^10.5.14",
"unfetch": "^4.2.0",
"unistore": "^3.5.2"
}
```

The combination which works is:

```json
"dependencies": {
"htm": "^3.1.0",
"preact": "10.2.0",
}
```

Can someone please help me figure this out? Version `10.2.0` came more than a year ago and I would like to use the latest version.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.