Skip to content

Commit

Permalink
server target
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1513 committed Feb 22, 2024
1 parent 52a511b commit 2ba7087
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/nthul/src/server/server-target/server-target.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import * as React from "react";
import { cookies } from "next/headers";
import { DEFAULT_ID } from "../../constants";
import type { ColorSchemePreference } from "../../hooks/use-theme";

interface ServerTargetProps {
children?: React.ReactNode;
tag?: keyof JSX.IntrinsicElements;
targetId?: string;
}

/**
* # ServerTarget
*
* --todo
* update comments
* create colorswitch
* update examples
*/
export function ServerTarget({ children }: ServerTargetProps) {
return (
<div>
<h1 data-testid="server-target-h1">server-target</h1>
{children}
</div>
);
export function ServerTarget({ tag, targetId }: ServerTargetProps) {
const key = targetId || DEFAULT_ID;
const [theme, csp, scs] = (cookies().get(key)?.value ?? ",system,light").split(",") as [

Check failure on line 20 in lib/nthul/src/server/server-target/server-target.tsx

View workflow job for this annotation

GitHub Actions / test

src/server/server-target/server-target.test.tsx > server-target > check if h1 heading exists

Error: Invariant: cookies() expects to have requestAsyncStorage, none available. ❯ Proxy.cookies ../../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next/src/client/components/headers.ts:41:11 ❯ ServerTarget src/server/server-target/server-target.tsx:20:29 ❯ renderWithHooks ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20

Check failure on line 20 in lib/nthul/src/server/server-target/server-target.tsx

View workflow job for this annotation

GitHub Actions / generate-docs

src/server/server-target/server-target.test.tsx > server-target > check if h1 heading exists

Error: Invariant: cookies() expects to have requestAsyncStorage, none available. ❯ Proxy.cookies ../../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next/src/client/components/headers.ts:41:11 ❯ ServerTarget src/server/server-target/server-target.tsx:20:29 ❯ renderWithHooks ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20

Check failure on line 20 in lib/nthul/src/server/server-target/server-target.tsx

View workflow job for this annotation

GitHub Actions / generate-docs

src/server/server-target/server-target.test.tsx > server-target > check if h1 heading exists

Error: Invariant: cookies() expects to have requestAsyncStorage, none available. ❯ Proxy.cookies ../../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next/src/client/components/headers.ts:41:11 ❯ ServerTarget src/server/server-target/server-target.tsx:20:29 ❯ renderWithHooks ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20

Check failure on line 20 in lib/nthul/src/server/server-target/server-target.tsx

View workflow job for this annotation

GitHub Actions / test

src/server/server-target/server-target.test.tsx > server-target > check if h1 heading exists

Error: Invariant: cookies() expects to have requestAsyncStorage, none available. ❯ Proxy.cookies ../../node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next/src/client/components/headers.ts:41:11 ❯ ServerTarget src/server/server-target/server-target.tsx:20:29 ❯ renderWithHooks ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:16305:18 ❯ mountIndeterminateComponent ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:20074:13 ❯ beginWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:21587:16 ❯ beginWork$1 ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:27426:14 ❯ performUnitOfWork ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26560:12 ❯ workLoopSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26466:5 ❯ renderRootSync ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:26434:7 ❯ recoverFromConcurrentError ../../node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom.development.js:25850:20
string,
ColorSchemePreference,
"dark" | "light",
];

const cls = `th-${theme} ${csp === "system" ? scs : csp}`;

const Tag = tag ?? "div";
return <Tag className={cls} data-nth="next" id={targetId ?? DEFAULT_ID} />;
}

0 comments on commit 2ba7087

Please sign in to comment.