Skip to content

make sure compat is triggered in new jsx runtime #3445

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

Merged
merged 1 commit into from
Feb 10, 2022
Merged

make sure compat is triggered in new jsx runtime #3445

merged 1 commit into from
Feb 10, 2022

Conversation

Austaras
Copy link
Contributor

preact relies on compat/render to be required/imported to generate compatible jsx object to react. This is generally enough, however as the current esm/cjs transistion, sometimes two copy of preact will exist in runtime for each kind of module. If compat is only imported once, everthing compat related would be broken.

This pr is not enough for compeletely fix this issue, but would make preact working when someone only import the new jsx function is imported. This is part of fix for gatsbyjs/gatsby#34783

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.626% when pulling 7b5f114 on Austaras:master into 1b6fbc7 on preactjs:master.

@developit
Copy link
Member

It might also be possible to ship this:

import { createElement, Fragment } from 'preact/compat';

function jsx(type, props, key, __source, __self) {
  const vnode = createElement(type, props);
  vnode.key = key;
  vnode.__source = __source;
  vnode.__self = __self;
  return vnode;
}

export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment };

@marvinhagemeister
Copy link
Member

@developit That's a neat idea! I'm leaning a little bit more to the approach chosen in this PR as using createElement inside jsx kinda defeats the purpose of using the new transform in the first place.

@marvinhagemeister marvinhagemeister merged commit dd1e86b into preactjs:master Feb 10, 2022
@marvinhagemeister
Copy link
Member

@Austaras Thank you so much for making a PR for this 🎉

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

Successfully merging this pull request may close these issues.

None yet

4 participants