-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Cloudflare Workers entrypoint and fix workerd/worker export conditions for tanstackstart-react #19461
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
Open
smorimoto
wants to merge
3
commits into
getsentry:develop
Choose a base branch
from
smorimoto:fix/tanstackstart-worker-export-conditions
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Cloudflare Workers entrypoint and fix workerd/worker export conditions for tanstackstart-react #19461
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,36 @@ | ||
| // import/export got a false positive, and affects most of our index barrel files | ||
| // can be removed once following issue is fixed: https://github.com/import-js/eslint-plugin-import/issues/703 | ||
| /* eslint-disable import/export */ | ||
| export * from '../client'; | ||
| export * from '../common'; | ||
|
|
||
| export { wrapFetchWithSentry } from '../server/wrapFetchWithSentry'; | ||
| export { wrapMiddlewaresWithSentry } from '../server/middleware'; | ||
| export { sentryGlobalRequestMiddleware, sentryGlobalFunctionMiddleware } from '../server/globalMiddleware'; | ||
|
|
||
| /** | ||
| * A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors | ||
| * so they should simply be a passthrough. | ||
| */ | ||
| export const ErrorBoundary = (props: React.PropsWithChildren<unknown>): React.ReactNode => { | ||
| if (!props.children) { | ||
| return null; | ||
| } | ||
|
|
||
| if (typeof props.children === 'function') { | ||
| return (props.children as () => React.ReactNode)(); | ||
| } | ||
|
|
||
| return props.children; | ||
| }; | ||
|
|
||
| /** | ||
| * A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch | ||
| * SSR errors so they should simply be a passthrough. | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export function withErrorBoundary<P extends Record<string, any>>( | ||
| WrappedComponent: React.ComponentType<P>, | ||
| ): React.FC<P> { | ||
| return WrappedComponent as React.FC<P>; | ||
| } | ||
smorimoto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
60 changes: 60 additions & 0 deletions
60
packages/tanstackstart-react/test/cloudflare/index.test.ts
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,60 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import * as CloudflareExports from '../../src/cloudflare/index'; | ||
|
|
||
| describe('Cloudflare entrypoint', () => { | ||
| describe('exports', () => { | ||
| it('exports wrapMiddlewaresWithSentry as a function (server implementation)', () => { | ||
| expect(typeof CloudflareExports.wrapMiddlewaresWithSentry).toBe('function'); | ||
|
|
||
| // The server implementation wraps middlewares with Sentry instrumentation. | ||
| // Verify it handles an empty object correctly (server impl returns an empty array). | ||
| const result = CloudflareExports.wrapMiddlewaresWithSentry({}); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('exports sentryGlobalRequestMiddleware as a middleware object with server handler', () => { | ||
| const middleware = CloudflareExports.sentryGlobalRequestMiddleware; | ||
| expect(middleware).toBeDefined(); | ||
| // The server implementation has a server handler function, unlike the client no-op stub. | ||
| expect(typeof middleware.options.server).toBe('function'); | ||
| }); | ||
|
|
||
| it('exports sentryGlobalFunctionMiddleware as a middleware object with server handler', () => { | ||
| const middleware = CloudflareExports.sentryGlobalFunctionMiddleware; | ||
| expect(middleware).toBeDefined(); | ||
| // The server implementation has a server handler function, unlike the client no-op stub. | ||
| expect(typeof middleware.options.server).toBe('function'); | ||
| }); | ||
|
|
||
| it('exports wrapFetchWithSentry', () => { | ||
| expect(typeof CloudflareExports.wrapFetchWithSentry).toBe('function'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ErrorBoundary', () => { | ||
| it('is a passthrough that returns children directly', () => { | ||
| const children = 'test child'; | ||
| const result = CloudflareExports.ErrorBoundary({ children }); | ||
| expect(result).toBe('test child'); | ||
| }); | ||
|
|
||
| it('returns null when no children are provided', () => { | ||
| const result = CloudflareExports.ErrorBoundary({}); | ||
| expect(result).toBeNull(); | ||
| }); | ||
|
|
||
| it('calls children when children is a function', () => { | ||
| const children = () => 'function result'; | ||
| const result = CloudflareExports.ErrorBoundary({ children }); | ||
| expect(result).toBe('function result'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('withErrorBoundary', () => { | ||
| it('is a passthrough that returns the original component', () => { | ||
| const MockComponent = () => null; | ||
| const result = CloudflareExports.withErrorBoundary(MockComponent); | ||
| expect(result).toBe(MockComponent); | ||
| }); | ||
| }); | ||
| }); |
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.