-
Notifications
You must be signed in to change notification settings - Fork 290
feat: add 'use client' directive to bundles for RSC support #1179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c985e9c
feat: add 'use client' directive to bundles for RSC support
gyaneshgouraw-okta 7688362
Merge branch 'main' into rsc-support-pr
gyaneshgouraw-okta 82b5c08
feat: add environment variable to assert 'use client' directive in CI…
gyaneshgouraw-okta 6006a02
ci: drop needs:build from rsc-directive job
gyaneshgouraw-okta c8baba2
Merge branch 'main' into rsc-support-pr
gyaneshgouraw-okta 458d004
Update EXAMPLES.md
gyaneshgouraw-okta 656bce9
Merge branch 'main' into rsc-support-pr
gyaneshgouraw-okta 346834f
ci: enhance CI workflow to upload and download build artifacts for do…
gyaneshgouraw-okta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * @jest-environment node | ||
| * | ||
| * React Server Components support. | ||
| * | ||
| * These assertions run against the BUILT bundles in dist/, not src/. The entry | ||
| * (src/index.tsx) is a re-export barrel with no directive of its own, and the | ||
| * 'use client' directives in the imported leaf modules are dropped when Rollup | ||
| * concatenates them into a single file, so the directive is injected at the | ||
| * bundle top via rollup's output.banner instead. The RSC-consumed entry points | ||
| * are the CJS (main) and ESM (module) outputs; the UMD <script> builds | ||
| * intentionally do NOT carry it. | ||
| * | ||
| * dist/ is not built by `npm test` (which is just `jest --coverage`). Locally, | ||
| * when the bundles are absent these tests skip with a clear message; run | ||
| * `npm run test:dist` to build first and assert against fresh output. Under CI | ||
| * (process.env.CI) missing bundles are a hard error rather than a silent skip, | ||
| * so the guarantee can never masquerade as a pass. Files are read as TEXT | ||
| * (never imported), so nothing here is pulled into coverage collection. | ||
| */ | ||
| import { existsSync, readFileSync } from 'fs'; | ||
| import { resolve } from 'path'; | ||
|
|
||
| const dist = (file: string): string => resolve(__dirname, '..', 'dist', file); | ||
|
|
||
| const firstNonEmptyLine = (file: string): string => { | ||
| const line = readFileSync(file, 'utf8') | ||
| .split('\n') | ||
| .map((l) => l.trim()) | ||
| .find((l) => l.length > 0); | ||
| if (line === undefined) { | ||
| throw new Error( | ||
| `Bundle ${file} has no non-empty lines (empty or truncated build output?)` | ||
| ); | ||
| } | ||
| return line; | ||
| }; | ||
|
|
||
| // A 'use client' directive is a bare string-literal statement, e.g. `'use client';` | ||
| // on its own line. It must NOT be confused with the same text appearing inside a | ||
| // JSDoc comment (the Auth0Provider doc block mentions the directive, and that prose | ||
| // is carried into every bundle). This matches a standalone directive only. | ||
| const hasClientDirective = (file: string): boolean => | ||
| readFileSync(file, 'utf8') | ||
| .split('\n') | ||
| .map((l) => l.trim()) | ||
| .some((l) => l === "'use client';" || l === '"use client";'); | ||
|
|
||
| const rscBundles = ['auth0-react.cjs.js', 'auth0-react.esm.js']; | ||
| const umdBundles = ['auth0-react.js', 'auth0-react.min.js']; | ||
|
|
||
| const distBuilt = [...rscBundles, ...umdBundles].every((f) => existsSync(dist(f))); | ||
|
|
||
| if (!distBuilt) { | ||
| if (process.env.CI) { | ||
| throw new Error( | ||
| "dist/ bundles are missing but CI must assert the 'use client' directive. " + | ||
| 'Ensure the build runs before jest (see the `test:dist` script / rsc-directive CI job).' | ||
| ); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| console.warn( | ||
| 'Skipping use-client-directive tests: dist/ not built. Run `npm run test:dist`.' | ||
| ); | ||
| } | ||
|
|
||
| const describeIfBuilt = distBuilt ? describe : describe.skip; | ||
|
|
||
| describeIfBuilt("'use client' directive in built bundles", () => { | ||
| it.each(rscBundles)('%s starts with the client directive', (file) => { | ||
| expect(firstNonEmptyLine(dist(file))).toBe("'use client';"); | ||
| }); | ||
|
|
||
| it.each(umdBundles)('%s does not carry the client directive', (file) => { | ||
| expect(hasClientDirective(dist(file))).toBe(false); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.