-
Notifications
You must be signed in to change notification settings - Fork 83
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
Improve bundle size with reader API in React server component environments #618
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa2b0ea
Start of fix for reader api bundle size
emmatown da4ff1c
Remove `'use client'`s from `@keystatic/core`
emmatown 6312d9c
Fix imports in checkbox field
emmatown 4fa8f31
Moving some exports around
emmatown a9ae234
Fix cloud image preview import
emmatown 2e2c9f7
Fix markdoc field imports
emmatown 92ab76e
Create witty-olives-obey.md
emmatown 35ff750
Update witty-olives-obey.md
emmatown 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 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 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
1 change: 1 addition & 0 deletions
1
packages/keystatic/src/component-blocks/blank-for-react-server.tsx
This file contains 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 @@ | ||
export function CloudImagePreview() {} |
2 changes: 0 additions & 2 deletions
2
packages/keystatic/src/component-blocks/cloud-image-preview.tsx
This file contains 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 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 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,32 @@ | ||
import { FieldDataError } from './fields/error'; | ||
import { PropValidationError } from './parse-props'; | ||
|
||
function flattenErrors(error: unknown): unknown[] { | ||
if (error instanceof AggregateError) { | ||
return error.errors.flatMap(flattenErrors); | ||
} | ||
return [error]; | ||
} | ||
|
||
export function formatFormDataError(error: unknown) { | ||
const flatErrors = flattenErrors(error); | ||
|
||
return flatErrors | ||
.map(error => { | ||
if (error instanceof PropValidationError) { | ||
const path = error.path.join('.'); | ||
return `${path}: ${ | ||
error.cause instanceof FieldDataError | ||
? error.cause.message | ||
: `Unexpected error: ${error.cause}` | ||
}`; | ||
} | ||
return `Unexpected error: ${error}`; | ||
}) | ||
.join('\n'); | ||
} | ||
|
||
export function toFormattedFormDataError(error: unknown) { | ||
const formatted = formatFormDataError(error); | ||
return new Error(`Field validation failed:\n` + formatted); | ||
} |
This file contains 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 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 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 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 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,21 @@ | ||
import { FormFieldInputProps } from '../../api'; | ||
import { Checkbox } from '@keystar/ui/checkbox'; | ||
import { Text } from '@keystar/ui/typography'; | ||
|
||
export function CheckboxFieldInput( | ||
props: FormFieldInputProps<boolean> & { | ||
label: string; | ||
description?: string; | ||
} | ||
) { | ||
return ( | ||
<Checkbox | ||
isSelected={props.value} | ||
onChange={props.onChange} | ||
autoFocus={props.autoFocus} | ||
> | ||
<Text>{props.label}</Text> | ||
{props.description && <Text slot="description">{props.description}</Text>} | ||
</Checkbox> | ||
); | ||
} |
This file contains 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 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 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 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 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 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
3 changes: 3 additions & 0 deletions
3
...s/keystatic/src/form/fields/document/DocumentEditor/primitives/blank-for-react-server.tsx
This file contains 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,3 @@ | ||
export function BlockWrapper() {} | ||
export function NotEditable() {} | ||
export function ToolbarSeparator() {} |
1 change: 0 additions & 1 deletion
1
packages/keystatic/src/form/fields/document/DocumentEditor/primitives/index.tsx
This file contains 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use client'; | ||
export { | ||
ActiveBlockPopoverProvider, | ||
BlockPopover, | ||
|
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use client'; | ||
|
||
import { Field, FieldProps } from '@keystar/ui/field'; | ||
import { useState } from 'react'; | ||
|
||
|
This file contains 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,30 @@ | ||
// this is used in react-server environments to avoid bundling UI when the reader API is used | ||
// if you added a new field and get an error that there's missing a missing export here, | ||
// you probably just need to add another empty export here | ||
|
||
function empty() { | ||
throw new Error( | ||
"unexpected call to function that shouldn't be called in React server component environment" | ||
); | ||
} | ||
|
||
export let SlugFieldInput = empty, | ||
TextFieldInput = empty, | ||
UrlFieldInput = empty, | ||
SelectFieldInput = empty, | ||
RelationshipInput = empty, | ||
PathReferenceInput = empty, | ||
MultiselectFieldInput = empty, | ||
IntegerFieldInput = empty, | ||
ImageFieldInput = empty, | ||
FileFieldInput = empty, | ||
DatetimeFieldInput = empty, | ||
DateFieldInput = empty, | ||
CloudImageFieldInput = empty, | ||
BlocksFieldInput = empty, | ||
DocumentFieldInput = empty, | ||
CheckboxFieldInput = empty, | ||
createEditorSchema = empty, | ||
getDefaultValue = empty, | ||
parseToEditorState = empty, | ||
serializeFromEditorState = empty; |
This file contains 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 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 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 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 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 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
1 change: 0 additions & 1 deletion
1
packages/keystatic/src/form/fields/markdoc/editor/editor-state.tsx
This file contains 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
1 change: 0 additions & 1 deletion
1
packages/keystatic/src/form/fields/markdoc/editor/markdoc/parse.ts
This file contains 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use client'; | ||
import { Ast, Node as MarkdocNode, ValidateError } from '@markdoc/markdoc'; | ||
import { | ||
Mark, | ||
|
1 change: 0 additions & 1 deletion
1
packages/keystatic/src/form/fields/markdoc/editor/markdoc/serialize.ts
This file contains 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
1 change: 0 additions & 1 deletion
1
packages/keystatic/src/form/fields/markdoc/editor/primitives/index.tsx
This file contains 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use client'; | ||
export { BlockPopover } from './BlockPopover'; | ||
|
||
export * from './toolbar'; |
This file contains 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use client'; | ||
import { css, tokenSchema } from '@keystar/ui/style'; | ||
import { | ||
DOMOutputSpec, | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels ... moderately unsustainable, if we end up with many more component blocks? could/should we organise this differently, like have an
component-blocks
import? or is this just private API and it doesn't matter, we can refactor it later if that's an issue?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, all of the
imports
field is entirely private