-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
expand on embedded mode #155
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { useEffect, useState } from "react" | ||
import { createPortal } from "react-dom" | ||
import { RemixDevTools, type RemixDevToolsProps } from "../RemixDevTools.js" | ||
import type { RdtClientConfig } from "../context/RDTContext.js" | ||
import { RDTEmbeddedContextProvider, type RdtClientConfig, useIsEmbeddedRDT } from "../context/RDTContext.js" | ||
import { hydrationDetector } from "./hydration.js" | ||
|
||
let hydrating = true | ||
|
@@ -19,34 +19,53 @@ function useHydrated() { | |
|
||
export const defineClientConfig = (config: RdtClientConfig) => config | ||
|
||
export const withDevTools = (Component: any, config?: RemixDevToolsProps) => () => { | ||
hydrationDetector() | ||
const hydrated = useHydrated() | ||
if (!hydrated) return <Component /> | ||
|
||
return ( | ||
<> | ||
<Component /> | ||
{createPortal(<RemixDevTools {...config} />, document.body)} | ||
</> | ||
) | ||
} | ||
|
||
/** | ||
* | ||
* @description Injects the dev tools into the Vite App, ONLY meant to be used by the package plugin, do not use this yourself! | ||
*/ | ||
export const withViteDevTools = (Component: any, config?: RemixDevToolsProps) => () => { | ||
hydrationDetector() | ||
function AppWithDevTools(props: any) { | ||
export const withDevTools = | ||
(Component: any, config?: RemixDevToolsProps & { panelMode?: "auto" | "embedded" }) => () => { | ||
hydrationDetector() | ||
const hydrated = useHydrated() | ||
const isEmbedded = useIsEmbeddedRDT() | ||
if (!hydrated) return <Component /> | ||
|
||
if ((config?.panelMode ?? "auto") === "embedded") { | ||
return ( | ||
<RDTEmbeddedContextProvider> | ||
<Component /> | ||
</RDTEmbeddedContextProvider> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<Component {...props} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not spreading the props over the component actually breaks RR7 support, I learned it the hard way yesterday with line 27 above breaking my rr7 test setup. So props need to be accepted and spread across Component in every return case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this withDevTools method is kind of low-key deprecated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
in favor of? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WithViteDevTools, this one is undocumented relic used to manually set it up if needed in remix v1, I plan to remove it fully in next major |
||
{createPortal(<RemixDevTools {...config} />, document.body)} | ||
<Component /> | ||
{!isEmbedded && createPortal(<RemixDevTools {...config} />, document.body)} | ||
</> | ||
) | ||
} | ||
return AppWithDevTools | ||
} | ||
|
||
/** | ||
* | ||
* @description Injects the dev tools into the Vite App, ONLY meant to be used by the package plugin, do not use this yourself! | ||
*/ | ||
export const withViteDevTools = | ||
(Component: any, config?: RemixDevToolsProps & { panelMode?: "auto" | "embedded" }) => () => { | ||
hydrationDetector() | ||
function AppWithDevTools(props: any) { | ||
const hydrated = useHydrated() | ||
if (!hydrated) return <Component /> | ||
if ((config?.panelMode ?? "auto") === "embedded") { | ||
return ( | ||
<RDTEmbeddedContextProvider> | ||
<Component /> | ||
</RDTEmbeddedContextProvider> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<Component {...props} /> | ||
{createPortal(<RemixDevTools {...config} />, document.body)} | ||
</> | ||
) | ||
} | ||
Comment on lines
+55
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been thinking, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then you in the vite plugin set it to embedded, that hides this createPortal, and wherever you use you just pass in a prop that the panel is embedded (inside the EmbeddedDevTools to the context) and you get this behavior with less hassle and there is 1 context to read from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Primarily because you really want React Context to be granular. One thing I was going to suggest to you was to separate the Having them both in the same context is inefficient, because every With that in mind, having a separate context for "embedded" mode makes sense, since the value of this is essentially static, a component that needs to render differently based on embedded-mode or not won't need to re-render whenever the state managed by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, makes sense, okay |
||
return AppWithDevTools | ||
} |
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.
why the default here? you don't really need to check if "auto" === "embedded"
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.
Mainly for clarity that the default mode is
"auto"
. It's not technically necessary, happy to remove it if preferred.