Skip to content

Commit

Permalink
fix(vite-plugin-admin): Ensure UI Routes are HMR (#7982)
Browse files Browse the repository at this point in the history
* fix(vite-plugin-admin): Ensure UI Routes are HMR

* cleanup
  • Loading branch information
kasperkristensen authored Jul 5, 2024
1 parent b24c850 commit 50df3ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
24 changes: 6 additions & 18 deletions packages/admin-next/admin-vite-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,28 +695,17 @@ export const medusaVitePlugin: MedusaVitePlugin = (options) => {
* We also need to reload all modules that import the route.
*/
if (!_extensionGraph.has(file)) {
const moduleId = getVirtualId(file)
const resolvedModuleId = resolveVirtualId(moduleId)
const module = server?.moduleGraph.getModuleById(resolvedModuleId)
if (module) {
await server?.reloadModule(module)
}
}

if (_extensionGraph.has(file)) {
const modules = _extensionGraph.get(file)

if (!modules) {
return
}

for (const moduleId of modules) {
const module = server?.moduleGraph.getModuleById(moduleId)
const imports = new Set<string>()

for (const resolvedModuleId of RESOLVED_ROUTE_MODULES) {
const module = server?.moduleGraph.getModuleById(resolvedModuleId)
if (module) {
imports.add(resolvedModuleId)
await server?.reloadModule(module)
}
}

_extensionGraph.set(file, imports)
}
}

Expand Down Expand Up @@ -813,7 +802,6 @@ export const medusaVitePlugin: MedusaVitePlugin = (options) => {
async load(id) {
if (RESOLVED_WIDGET_MODULES.includes(id)) {
const zone = getWidgetZone(id)

return register(id, { type: "widget", get: zone })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import * as Collapsible from "@radix-ui/react-collapsible"
import { useTranslation } from "react-i18next"

import { useStore } from "../../../hooks/api/store"
import { settingsRouteRegex } from "../../../lib/extension-helpers"
import { Divider } from "../../common/divider"
import { Skeleton } from "../../common/skeleton"
import { NavItem, NavItemProps } from "../../layout/nav-item"
import { Shell } from "../../layout/shell"

import routes from "virtual:medusa/routes/links"
import { settingsRouteRegex } from "../../../lib/extension-helpers"
import { Divider } from "../../common/divider"

export const MainLayout = () => {
return (
Expand Down Expand Up @@ -173,9 +173,9 @@ const ExtensionRouteSection = () => {

const links = routes.links

const extensionLinks = links.filter(
(link) => !settingsRouteRegex.test(link.path)
)
const extensionLinks = links
.filter((link) => !settingsRouteRegex.test(link.path))
.sort((a, b) => a.label.localeCompare(b.label))

if (!extensionLinks.length) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const PriceListDetailsForm = ({ form }: PriceListDetailsFormProps) => {
<StackedFocusModal.Trigger asChild>
<button
type="button"
className="bg-ui-bg-field shadow-borders-base txt-compact-small text-ui-fg-muted flex flex-1 items-center gap-x-2 rounded-md px-2 py-1.5"
className="bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover shadow-borders-base txt-compact-small text-ui-fg-muted transition-fg focus-visible:shadow-borders-interactive-with-active flex flex-1 items-center gap-x-2 rounded-md px-2 py-1.5 outline-none"
>
<MagnifyingGlass />
{t(
Expand Down

0 comments on commit 50df3ce

Please sign in to comment.