Skip to content

Commit

Permalink
chore: improve test-dep-cjs (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Dec 15, 2024
1 parent c091d41 commit c250fc5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion packages/react-server/examples/basic/deps/cjs/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ import React from "react";
import dep from "./client-dep.cjs";

export function TestClient() {
return React.createElement("span", null, dep.test);
return React.createElement("span", null, useHydrated() ? dep.test : "[...]");
}

function useHydrated() {
return React.useSyncExternalStore(
React.useCallback(() => () => {}, []),
() => true,
() => false,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";

const MyContext = React.createContext("not-ok");

export function MyContextProvider(props) {
export function TestClientProvider(props) {
return React.createElement(
MyContext.Provider,
{ value: "ok" },
Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/examples/basic/deps/context/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { MyContextProvider } from "./client.js";
import { TestClientProvider } from "./client.js";

export function TestServer(props) {
return React.createElement(MyContextProvider, null, props.children);
return React.createElement(TestClientProvider, null, props.children);
}
4 changes: 2 additions & 2 deletions packages/react-server/examples/basic/deps/context/server2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// difference from `server.js` is that
// this uses self exports reference `@hiogawa/test-dep-context/client`
// instead of relative reference `./client.js`
import { MyContextProvider } from "@hiogawa/test-dep-context/client";
import { TestClientProvider } from "@hiogawa/test-dep-context/client";
import React from "react";

// consume own provider in server entr
export function TestServer(props) {
return React.createElement(MyContextProvider, null, props.children);
return React.createElement(TestClientProvider, null, props.children);
}

0 comments on commit c250fc5

Please sign in to comment.