Skip to content

Commit

Permalink
fix: server functions test
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Dec 2, 2023
1 parent d8ef7c9 commit c0be45f
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 99 deletions.
2 changes: 2 additions & 0 deletions packages/vinxi-devtools/dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createApp } from "vinxi";
import { config } from "vinxi/plugins/config";
import inspect from "vite-plugin-inspect";
import solid from "vite-plugin-solid";

import { devtoolsClientDev } from "./devtools-dev.js";
import { devtoolsRpc } from "./index.js";
Expand All @@ -15,6 +16,7 @@ export default createApp({
target: "browser",
plugins: () => [
inspect(),
solid(),
config("test-spa", {
build: {
rollupOptions: {
Expand Down
64 changes: 27 additions & 37 deletions packages/vinxi-devtools/devtools-client.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {
Box,
Button,
Container,
Flex,
Theme,
ThemePanel,
} from "@radix-ui/themes";
import "@radix-ui/themes/styles.css";
import { A, Route, Router, Routes } from "@solidjs/router";
import "@unocss/reset/tailwind.css";
import { cva } from "class-variance-authority";
import { clsx } from "clsx";
import { use } from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter, Link, NavLink, Route, Routes } from "react-router-dom";
import { render } from "solid-js/web";
import { twMerge } from "tailwind-merge";
import "virtual:uno.css";

Expand Down Expand Up @@ -97,7 +88,7 @@ const buttonVariants = cva(

function Devtools() {
return (
<Theme appearance="dark">
<div className="dark-mode">
<div className="h-screen w-full flex flex-col bg-sky1 font-sans n-panel-grids">
{/* <div className="flex items-center justify-between px-4 py-2 border-b border-gray-200 dark:border-gray-700">
<h1 className="font-semibold text-lg text-gray-800 dark:text-gray-200">
Expand All @@ -107,33 +98,29 @@ function Devtools() {
<div className="flex flex-1 overflow-hidden">
<div className="border-r n-border-base text-sky1-fg w-12 flex flex-col gap-1 items-center py-1 n-bg-base">
<div className="py-1 border-b n-border-base w-full flex items-center justify-center">
<NavLink
className={({ isActive }) =>
buttonVariants({
variant: "ghost",
size: "sm",
className: isActive ? "text-sky8" : null,
})
}
to={`/index.html`}
<A
activeClass={buttonVariants({
variant: "ghost",
size: "sm",
className: "text-sky8",
})}
href={`/index.html`}
>
<VinxiLogo />
</NavLink>
</A>
</div>

{plugins.map((plugin) => (
<NavLink
className={({ isActive }) =>
buttonVariants({
variant: "ghost",
size: "sm",
className: isActive ? "text-sky8" : null,
})
}
to={`/${plugin.id}`}
<A
className={buttonVariants({
variant: "ghost",
size: "sm",
className: "text-sky8",
})}
href={`/${plugin.id}`}
>
<span className={cn(plugin.icon, "text-lg")} />
</NavLink>
</A>
))}
</div>
<Routes>
Expand All @@ -156,7 +143,7 @@ function Devtools() {
</Routes>
</div>
</div>
</Theme>
</div>
);
}

Expand Down Expand Up @@ -199,8 +186,11 @@ function Input({ icon, ...props }) {
);
}

createRoot(document.getElementById("devtools")).render(
<BrowserRouter basename="/__devtools/client">
<Devtools />
</BrowserRouter>,
render(
() => (
<Router base="/__devtools/client">
<Devtools />
</Router>
),
document.getElementById("devtools"),
);
4 changes: 2 additions & 2 deletions packages/vinxi-devtools/devtools-dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import react from "@vitejs/plugin-react";
import unocss from "unocss/vite";
import { config } from "vinxi/plugins/config";
import solid from "vite-plugin-solid";

import { fileURLToPath } from "node:url";

Expand All @@ -16,7 +16,7 @@ export const devtoolsClientDev = () => {
base: "/__devtools/client",
plugins: () => [
unocss(unocssConfig),
react(),
solid(),
{
name: "remove-vinxi-inject",
config(config) {
Expand Down
1 change: 0 additions & 1 deletion packages/vinxi-devtools/dist/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ async function mount() {
]
})
}),
"$",
isOpen ? o3("div", {
className: "nuxt-devtools-frame",
style: {
Expand Down
40 changes: 19 additions & 21 deletions packages/vinxi-devtools/mount.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fragment, h, render } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
import { createEffect, createSignal } from "solid-js";
import { render } from "solid-js/web";

import style from "./style.css?raw";

Expand Down Expand Up @@ -97,11 +97,10 @@ export default async function mount() {
// };

function App(props) {
const [isOpen, setIsOpen] = useState(false);
const ref = useRef();

const [isHovering, setIsHovering] = useState(false);
useEffect(() => {
const [isOpen, setIsOpen] = createSignal(true);
let ref;
const [isHovering, setIsHovering] = createSignal(false);
createEffect(() => {
// autoAnimate(ref.current, (el, action, oldCoords, newCoords) => {
// console.log(action);
// let keyframes;
Expand Down Expand Up @@ -167,21 +166,21 @@ export default async function mount() {
// });
// });
// autoAnimate(ref.current);
}, [ref.current]);
});
return (
<>
<style>{style}</style>
<div
id="nuxt-devtools-anchor"
className={!isHovering ? "nuxt-devtools-hide" : ""}
// className={!isHovering ? "nuxt-devtools-hide" : ""}
style={{
left: "50%",
}}
onMouseMove={() => {
setIsHovering(true);
}}
>
<div className="nuxt-devtools-glowing" />
<div class="nuxt-devtools-glowing" />
<div
ref={ref}
className="nuxt-devtools-panel"
Expand Down Expand Up @@ -221,29 +220,28 @@ export default async function mount() {
</defs>
</svg>
</div>
$
{isOpen ? (
{isOpen() ? (
<div
className="nuxt-devtools-frame"
class="nuxt-devtools-frame"
style={{
position: "absolute",
bottom: "1rem",
left: "0px",
zIndex: 9999998,
"z-index": 9999998,
transform: "translate(-50%, 0)",
backgroundColor: "black",
"background-color": "black",
width: "70vw",
borderRadius: "0.5rem",
"border-radius": "0.5rem",
height: "45vh",
border: "1px solid #3336",
display: "flex",
flexDirection: "row",
"flex-direction": "row",
overflow: "hidden",
transition: "all",
alignItems: "center",
justifyContent: "center",
"align-items": "center",
"justify-content": "center",
// nice box shadow
boxShadow: "rgba(99, 99, 99, 0.2) 0px 8px 16px 0px",
"box-shadow": "rgba(99, 99, 99, 0.2) 0px 8px 16px 0px",
}}
>
<iframe src="/__devtools/client/index.html" />
Expand All @@ -254,5 +252,5 @@ export default async function mount() {
);
}

render(<App />, shadow.shadowRoot);
render(() => <App />, shadow.shadowRoot);
}
48 changes: 21 additions & 27 deletions packages/vinxi-devtools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"allowJs": true,
"checkJs": true,
"noEmit": false,
"jsx": "react-jsx",
"isolatedModules": true,
"strict": true,
"declarationMap": true,
"declaration": true,
"skipLibCheck": true,
"emitDeclarationOnly": true,
"types": [
"react/experimental",
"react-dom/experimental",
"vinxi/types/client"
],
"outDir": "./dist/types"
},
"include": [
"./mount.jsx",
"./index.js"
]
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"allowJs": true,
"checkJs": true,
"noEmit": false,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"isolatedModules": true,
"strict": true,
"declarationMap": true,
"declaration": true,
"skipLibCheck": true,
"emitDeclarationOnly": true,
"types": ["vinxi/types/client"],
"outDir": "./dist/types"
},
"include": ["./mount.jsx", "./index.js"]
}
2 changes: 1 addition & 1 deletion packages/vinxi-server-functions/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { server } from "./server.js";
export const serverFunctions = {
client: client,
server: server,
router: ({ runtime, ...overrides }) => ({
router: ({ runtime, ...overrides } = {}) => ({
name: "server-fns",
mode: "handler",
base: "/_server",
Expand Down
14 changes: 14 additions & 0 deletions test/templates/react-srv-fn/app/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
async function greetServer(name: string) {
"use server";
console.log(`Hi, server. My name is ${name}.`);
}

export function App() {
return (
<div>
<button onClick={() => greetServer("client")} data-test-id="button">
Greet Server
</button>
</div>
);
}
12 changes: 2 additions & 10 deletions test/templates/react-srv-fn/app/client.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
/// <reference types="vinxi/types/client" />
import ReactDOM from "react-dom/client";
import { App } from "./App";

async function greetServer(name: string) {
"use server";
console.log(`Hi, server. My name is ${name}.`);
}

ReactDOM.createRoot(document.getElementById("root")).render(
<div>
<button onClick={() => greetServer("client")} data-test-id="button">Greet Server</button>
</div>,
);
ReactDOM.createRoot(document.getElementById("root")).render(<App />);

0 comments on commit c0be45f

Please sign in to comment.