-
Notifications
You must be signed in to change notification settings - Fork 25
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
#7670: Simplify injection of widgets onto the page (renderWidget
)
#8150
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8150 +/- ##
==========================================
+ Coverage 73.37% 73.44% +0.06%
==========================================
Files 1314 1316 +2
Lines 40722 40735 +13
Branches 7571 7575 +4
==========================================
+ Hits 29879 29916 +37
+ Misses 10843 10819 -24 ☔ View full report in Codecov by Sentry. |
const style = document.createElement("style"); | ||
}> = ({ url, controller, onOutsideClick }) => { | ||
const aborted = useAbortSignal(controller.signal); | ||
useScrollLock(!aborted); |
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.
In this file:
- replace explicit
attachShadow()
call withrenderWidget()
's own - replace inline solution with existing
useScrollLock()
}; | ||
}, | ||
() => signal.aborted, | ||
); |
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.
Likewise, we can use useSyncExternalStore
to deal with promises too. I think the whole useAsyncState
can be replaced with two useSyncExternalStore
calls in 15 lines of code.
const containerStyle = { | ||
zIndex: NOTIFICATIONS_Z_INDEX, | ||
fontFamily: "sans-serif", | ||
} satisfies React.CSSProperties; |
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 just moved this out of the init.
signal.addEventListener("abort", () => { | ||
root.remove(); | ||
unmountComponentAtNode(root); | ||
}); |
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.
This code is what we have repeated several times in the codebase, with various level of support and conflict prevention. renderWidget
makes this more transparent and in React 18 we'll be able to skip the wrapper element too.
renderWidget
)
No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack. Do not edit this comment manually. |
Tested again, it works. However I realized that we want notifications to survive context invalidation since we use them to inform the user: pixiebrix-extension/src/errors/contextInvalidated.ts Lines 29 to 33 in 88e004b
So I added a |
What does this PR do?
This helper:
avoids the additional wrapper created outside React that cause regularly causes conflictsI expect most isolated components to use both the
IsolatedWidget
component (#7670) andrenderWidget
:Future work
ReactDOM.render()
usage here, particularly the popover utils will have the most benefit complexity-wiseChecklist