Skip to content

Commit

Permalink
fix: usage of Context
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Dec 18, 2024
1 parent 209dc52 commit 6f5def8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions demo/tiddlers/docs/useRenderTiddler.tid
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { IDefaultWidgetProps, ParentWidgetContext } from '$:/plugins/linonetwo/t
...

return (
<ParentWidgetContext.Provider value={props.parentWidget}>
<ParentWidgetContext value={props.parentWidget}>
<YourComponents />
</ParentWidgetContext.Provider>
</ParentWidgetContext>
);
```

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useRenderTiddler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useRenderTiddler(tiddlerTitle: string, containerReference: RefOb
}
if (parentWidget === undefined) {
throw new Error(
'Your plugin have a bug: `parentWidget` is undefined, you should use `<ParentWidgetContext.Provider value={props.parentWidget}>`, see tw-react for document.',
'Your plugin have a bug: `parentWidget` is undefined, you should use `<ParentWidgetContext value={props.parentWidget}>`, see tw-react for document.',
);
}
if (options?.skip === true) {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useWidget(parseTreeNode: IParseTreeNode, containerReference: Ref
}
if (parentWidget === undefined) {
throw new Error(
'Your plugin have a bug: `parentWidget` is undefined, you should use `<ParentWidgetContext.Provider value={props.parentWidget}>`, see tw-react for document.',
'Your plugin have a bug: `parentWidget` is undefined, you should use `<ParentWidgetContext value={props.parentWidget}>`, see tw-react for document.',
);
}
if (options?.skip === true) {
Expand Down
9 changes: 2 additions & 7 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ if (typeof window !== 'undefined') {
global.React = React;
}

// DEBUG: console ReactDom
console.log(`ReactDom`, ReactDom);
// DEBUG: console ReactDomClient
console.log(`ReactDomClient`, ReactDomClient);

class ReactWidgetImpl<
IProps extends ITWReactProps = ITWReactPropsDefault,
> extends Widget implements IReactWidget<IProps> {
Expand Down Expand Up @@ -99,7 +94,7 @@ class ReactWidgetImpl<
if (this.reactComponent === undefined || this.reactComponent === null) {
return;
}
if (this.root === undefined) {
if (this.root === undefined && this.parentDomNode !== undefined) {
const nextSibling = this.findNextSiblingDomNode();
this.render(this.parentDomNode, nextSibling);
return;
Expand All @@ -111,7 +106,7 @@ class ReactWidgetImpl<
currentProps.parentWidget = this;
}
const reactElement = React.createElement(this.reactComponent, currentProps);
this.root.render(reactElement);
this.root?.render?.(reactElement);
}

destroy() {
Expand Down

0 comments on commit 6f5def8

Please sign in to comment.