-
-
Notifications
You must be signed in to change notification settings - Fork 910
Add onComplete callback for completing processing in MarkdownHooks #913
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not really for or against this change. I see why it’s useful, but I also wonder if we should add such features. react-markdown
is a relatively simple, high-level library. All the pieces are available in the unified ecosystem to build a more specialized integration if the user needs it.
Please open a new issue before PR next time. |
Let's convert this PR into draft and discuss with other maintainers there then. By the way, the CI is still broken. |
Unfortunately I was not able to understand what the CI error is. All tests went well but it gives the following error: |
You didn't provide a new test case for |
I won't block this, but am not sure I'd recommend it either. I don't think JS is needed to make a typing animation, CSS can likely work well enough, see https://github.com/orgs/remarkjs/discussions/1321 and https://github.com/orgs/remarkjs/discussions/1310
names like
The tests measure code coverage https://en.wikipedia.org/wiki/Code_coverage |
If this was done, I: a) worry about the name; b) think that probably no parameters should be passed at all? c) there is no error handling; d) there should probably be a result handling? But importantly, I worry what this is for. Have you actually tried to use this? It looks like it could be abused to change the DOM that we control. And I think this sets expectations to users that they can modify file/tree/error but it wouldn’t actually do what they wanted. |
I switched from using CSS to using motion with https://motion.dev/docs/react-transitions#staggerchildren (which I believe still uses mostly CSS) because I needed to intercept some animation events (for example the completion of the animation of the entire text and certain elements of the text such as punctuation) and give the user the possibility to have total control of the animations in an easy way.
In any case I imagine that also in other cases those who are using MarkdownHooks might need to know if the user has viewed the text or just the loading. For example in a very common case that is the management of notifications (with a very long text), in particular if it has been read or not. Those who are using MarkdownHooks to display the text of messages might need to notify the bakend that the message has been read by the user only after MarkdownHooks has finished loading. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #913 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 1743 1770 +27
Branches 123 125 +2
=========================================
+ Hits 1743 1770 +27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Note that in the callback, it hasn’t been rendered. Only the React state was just updated. There are ways to actually know when it’s done rendering. For example, import { Root } from 'hast'
import { createContext, ReactNode, Ref, use, useState } from 'react'
const RenderedContext = createContext<Ref<HTMLSpanElement>>()
function Span({ 'data-rendered': rendered, ...props }): ReactNode {
return <span {...props} ref={rendered ? use(RenderedContext) : null} />
}
const components = {
span: Span
}
function rehypeRenderedIndicator() {
return (ast: Root) => {
ast.children.push({
type: 'element',
tagName: 'span',
properties: {
'data-rendered': 'true'
},
children: [],
})
}
}
const rehypePlugins = [rehypeRenderedIndicator]
function App(): ReactNode {
const [rendered, setRendered] = useState<HTMLSpanElement>()
return (
<RenderedContext value={setRendered}>
<MarkdownHooks rehypePlugins={rehypePlugins}>{''}</MarkdownHooks>
</RenderedContext>
)
} |
This proposed feature is not a good solution for that use case |
@wooorm, Why? Is the problem where the The fact of not giving the possibility to access the file, hast and error, and the fact that the name onComplete could be not apriopiated, I can understand and honestly for me it is indifferent. However I did not understand if there are cons on the fact of adding a function to notify the developer of the completion. |
Initial checklist
Description of changes
Add onComplete callback for completing processing in MarkdownHooks
close #912