diff --git a/tests/server-contexts/.gitignore b/tests/server-contexts/.gitignore new file mode 100644 index 0000000..fd3dbb5 --- /dev/null +++ b/tests/server-contexts/.gitignore @@ -0,0 +1,36 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js +.yarn/install-state.gz + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/tests/server-contexts/app/after/FirstComponent.tsx b/tests/server-contexts/app/after/FirstComponent.tsx new file mode 100644 index 0000000..e6cd99b --- /dev/null +++ b/tests/server-contexts/app/after/FirstComponent.tsx @@ -0,0 +1,16 @@ +import getServerContext from "next-impl-getters/get-server-context"; +import { sleep } from "../../tools/sleep"; +import { AfterContext } from "../../components/AfterContext"; + +const FirstComponent = async () => { + await sleep(1000); + const context = getServerContext(AfterContext); + + return ( +
+ {context?.after} +
+ ) +} + +export default FirstComponent; diff --git a/tests/server-contexts/app/after/page.tsx b/tests/server-contexts/app/after/page.tsx new file mode 100644 index 0000000..f774e96 --- /dev/null +++ b/tests/server-contexts/app/after/page.tsx @@ -0,0 +1,23 @@ +import Nav from "../../components/Nav"; +import { AfterContext } from "../../components/AfterContext"; +import FirstComponent from "./FirstComponent"; + +export default function Page() { + return ( +
+
+ {context?.inside} +
+ ) +} + +export default SecondComponent; diff --git a/tests/server-contexts/app/inside/page.tsx b/tests/server-contexts/app/inside/page.tsx new file mode 100644 index 0000000..45bff38 --- /dev/null +++ b/tests/server-contexts/app/inside/page.tsx @@ -0,0 +1,23 @@ +import Nav from "../../components/Nav"; +import { InsideContext } from "../../components/InsideContext"; +import SecondComponent from "./SecondComponent"; + +export default function Page() { + return ( ++ {serverContext?.inside} +
+ )} ++ {context?.uninitialized} +
+ ) +} + +export default SecondComponent; diff --git a/tests/server-contexts/app/uninitialized/page.tsx b/tests/server-contexts/app/uninitialized/page.tsx new file mode 100644 index 0000000..fc5b212 --- /dev/null +++ b/tests/server-contexts/app/uninitialized/page.tsx @@ -0,0 +1,22 @@ +import getServerContext from "next-impl-getters/get-server-context"; +import Nav from "../../components/Nav"; +import { UninitializedContext } from "../../components/UninitializedContext"; +import SecondComponent from "./SecondComponent"; + +export default function Page() { + return ( ++ {serverContext?.uninitialized} +
+ )} +