|
1 | 1 | # Next JS example |
2 | 2 |
|
3 | | -This example shows the use of the [`react-pointcuts`](../../packages/react-pointcuts/docs/README.md), [`features`](../../packages/features/docs/README.md) and [`webpack`](../../packages/webpack/docs/README.md) packages, as part of an ["app router"](https://nextjs.org/docs/app) [Next.js](https://nextjs.org/) application. |
| 3 | +These examples show the use of the [`react-pointcuts`](../../packages/react-pointcuts/docs/README.md), [`features`](../../packages/features/docs/README.md) and [`webpack`](../../packages/webpack/docs/README.md) packages, as part of an ["app router"](https://nextjs.org/docs/app) [Next.js](https://nextjs.org/) application. |
4 | 4 |
|
5 | 5 | N.B. NextJs support is currently experimental, see [caveats](#caveats). |
6 | 6 |
|
7 | | -## Setup |
| 7 | +## Examples |
8 | 8 |
|
9 | | -It is using a contrived point cut plugin, replicating an Optimizely activation handler: |
| 9 | +1. [content management](./src/app/fixtures/content-management/README.mdx) |
10 | 10 |
|
11 | | -```js |
12 | | -{ |
13 | | - onCodeSelected: ({ matchedFeatures }) => { |
14 | | - if (matchedFeatures?.length) { |
15 | | - const [[feature]] = matchedFeatures; |
16 | | - console.log( |
17 | | - `activated ${feature} with audience ${getFeatures().audience}` |
18 | | - ); |
19 | | - } |
20 | | - } |
21 | | -} |
22 | | -``` |
| 11 | + This is a basic example demonstrating the ability to vary react hooks, using a contrived content management feature. |
23 | 12 |
|
24 | | -...which logs the activation event normally destined for the toggle router (Optimizely) to the console. |
| 13 | +2. [experiments](./src/app/fixtures/experiments/README.mdx) |
25 | 14 |
|
26 | | -A contrived server function called `getExperiments` exists to parse inbound headers containing experiments, used to drive the toggling. |
27 | | -
|
28 | | -## Usage |
29 | | -
|
30 | | -(from the `examples/next` folder of the monorepo) |
31 | | -
|
32 | | -1. install [mod header](https://modheader.com/), or some other tool for modifying request headers sent in a browser |
33 | | -2. `npm install` |
34 | | -4. `npm run dev` |
35 | | -5. open `localhost:3000/fixtures/experiments` in a browser |
36 | | -
|
37 | | -See appropriate documentation within [the examples folder](./src/app/fixtures/experiments/README.md). |
38 | | -
|
39 | | -N.B. To confirm the `experiments` header you've set with `mod header`, you can add `?showExperiments=true` to the URL to render the value to the top of the page. |
40 | | -If you're not seeing the experiments header show up, try refreshing the page. NextJs is perhaps pre-caching the pages. |
| 15 | + These examples show various toggle setups with react components being varied, opting out of variation, etc. |
41 | 16 |
|
42 | 17 | ## Caveats |
43 | 18 |
|
44 | | -- Only client components are supported, since request-bound context is not supported by server components. They are not meant to be stateful. |
45 | | - - API routes may be supportable, via use of [an async local storage wrapper](https://github.com/rexfordessilfie/nextwrappers/tree/main/packages/async-local-storage), once support for named exports is added ([Issue #4](https://github.com/ASOS/web-toggle-point/issues/4)) - since would need to match the HTTP verbs. |
46 | | -- The webpack package cannot currently vary NextJs managed files such as [pages](https://nextjs.org/docs/app/building-your-application/routing/pages) themselves, but can vary modules they import ([Issue #9](https://github.com/ASOS/web-toggle-point/issues/9)). |
| 19 | +- Only client components can be toggled using a per-request features store, since request-bound context is not supported by server components. They are not meant to be stateful |
| 20 | + - API routes may be supportable, via use of [an async local storage wrapper](https://github.com/rexfordessilfie/nextwrappers/tree/main/packages/async-local-storage), once support for named exports is added ([Issue #4](https://github.com/ASOS/web-toggle-point/issues/4)) - since would need to match the HTTP verbs |
| 21 | +- The webpack package cannot currently vary some of NextJs' [filesystem convention files](https://nextjs.org/docs/pages/getting-started/project-structure#files-conventions) ([Issue #9](https://github.com/ASOS/web-toggle-point/issues/9)) |
47 | 22 | - The `webpack` plugin uses webpack hooks, so is incompatible with the new TurboPack bundler |
48 | | -- The `webpack` plugin uses Node JS APIs to access the filesystem, so may be incompatible with [the edge runtime](https://nextjs.org/docs/app/api-reference/edge#unsupported-apis). |
| 23 | +- The `webpack` plugin uses Node JS APIs to access the filesystem, so may be incompatible with [the edge runtime](https://nextjs.org/docs/app/api-reference/edge#unsupported-apis) |
| 24 | +- The `nodeRequestScopedFeaturesStoreFactory` from the [`features`](../../packages/features/docs/README.md) package relies on singleton values held in top-level scope, which Next does not support. See [issue 50](https://github.com/ASOS/web-toggle-point/issues/50), which should remedy this. |
0 commit comments