-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Providing context to generated components in Solid doesn't work #49
Comments
I dunno, Solid does things differently, I am not an export on what it does. If it does things wildly differently, perhaps that should be changed there? I would typically recommend against context. Context is often not needed. Perhaps you can do something along these lines: import {JSX, createSignal, onMount} from "solid-js";
import "./App.css";
import { unified } from "unified";
import rehypeParse from "rehype-parse";
import rehypeReact from "rehype-react";
import { Fragment, jsx, jsxs } from "solid-js/h/jsx-runtime";
function App() {
const [content, setContent] = createSignal<JSX.Element>();
onMount(async () => {
const value = "Hello World"
const processor = unified()
.use(rehypeParse, { fragment: true })
.use(rehypeReact, {
Fragment,
jsx,
jsxs,
elementAttributeNameCase: "html",
stylePropertyNameCase: "css",
components: {
div: () => {
return <div>Context: {value}</div>;
},
},
});
const file = await processor.process(`
<h1>Hello World</h1>
<div></div>
`);
setContent(file.result);
});
return (
<div>{content()}</div>
);
}
export default App; |
Regardless of the use of context, doesn't the warning Even if we can't really solve this right now, it might be worth putting a note in docs to acknowledge that this doesn't work as expected. |
This tool supports some form of a contract, that contract is governed by React, the automatic JSX runtime. But all frameworks follow that contract, they say they do. Now, if one framework doesn’t support some of its features in some cases, to me that is out of scope to this project. It’s on Solid to support this JSX contract. I would rather you raise this problem where it is, so that it can be fixed, instead of turning this readme into an issue tracker for Solid? |
I'll raise this issue on the Solid side. I agree that this repo isn't the best place to solve this issue. But because of the focused nature of this repo (in contrast with https://github.com/solidjs/solid) and because the instructions and examples for using rehype-react with Solid live here and in https://github.com/syntax-tree/hast-util-to-jsx-runtime, it makes sense to me to warn users of the current limitations here. They will probably run into these issues eventually, and that might prompt them to look at the solid issue tracker, but having a short warning in this repo's README might save them some time. If you'd like, we can also add a link to the issue I'll create on the solid side so that users know where to access the most up to date info. |
Few things live here? 😅 I understand that you want this project to work with Solid. But I don’t want to be an issue tracker for Solid. |
Hi! This was closed. Team: If this was fixed, please add |
This solves the issue: solidjs/solid#2394 (comment) SolidJS was unable to update the content correctly because using |
Initial checklist
Affected package
rehype-react@8.0.0
Steps to reproduce
Minimal reproducible example: https://codesandbox.io/p/devbox/mjnc4d
(no extra steps are required).
Actual behavior
It looks like a new reactive environment/context (whatever it's called) for Solid is being created based on this warning in browser's console:
computations created outside a 'createRoot' or 'render' will never be disposed
and the fact that context (usingcreateContext
) isn't passed down to components inserted through the components option ofrehypeReact
.This is in contrast with
rehype-react
+ React, with which it's possible to access context inside these inserted components.Expected behavior
I expect the value of
MyContext
, set byMyContext.Provider
, to be accessible inside interactive components inserted byrehype-react
.This is needed (I believe) for my use-case since I'm trying to render books (in asciidoc) with stateful, interactive content, and the content state needs to be saved on a per-user basis. Therefore I'm trying to use Context to pass user-specific data to the interactive components.
Runtime
node@20.12.0; Chrome (Brave): 1.73.89 Chromium: 131.0.6778.69 (Official Build) (64-bit)
Package manager
npm@10.5.0
Operating system
Arch Linux (kernel: 6.6.67-1-lts)
Build and bundle tools
Vite
The text was updated successfully, but these errors were encountered: