esxjs / esx

Like JSX, but native and fast
MIT License
654 stars 11 forks source link

esx.renderToString not working with element created in another instance #11

Closed irudoy closed 5 years ago

irudoy commented 5 years ago

esx.renderToString throws "%component% not found in registered components" when ESX element that was created in another ESX instance has been passed. I understand that it's kinda unusual case, but as from description of this project:

It can be used with absolutely no code base changes.

Example

// index.js
const esx = require('esx')()
const getElement = require('./getElement')
console.log(esx.renderToString(getElement('hi')))
// getElement.js
const esx = require('esx')()
const Say = ({ word }) => esx`<div>${word}</div>`
esx.register({ Say })
module.exports = word => esx`<Say word=${word} />`

Output

ReferenceError: ESX: Say not found in registered components

Repository with repro

https://github.com/irudoy/esx-repro

davidmarkclements commented 5 years ago

yeah legit bug and thanks for such a straight forward reproducible case

while this is being fixed, it can be worked around by nesting the returned element in a fragment inside an esx tag literal

console.log(esx.renderToString(esx `<>${getElement('hi')}</>`))
davidmarkclements commented 5 years ago

fixed in v2.3.2 - no perf hit, :D