-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix @keystone-6/fields-document
package breaking when compiling in SSR environments
#9041
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 3de0ecf:
|
I am really open to accepting this work, my only concern is that we're trying to solve a number of problems in one pull request. |
Can you please put any code moving operations into their own commits, so I can easily review those commits and then focus only on the diff? |
Unfortunately this is not possible. Everything here is related and do not function without other pieces. EDIT: The best I can do is to move changes in
This is already kind of the case. The initial ~18 "wip" labelled commits are splitting one file and then changing related imports in other places. My workflow was like this:
|
Removed all changes to |
@marekryb OK, if you can get everything into a working order, as atomic as reasonable, I could jump in towards the end |
fields-document
package to fix server-side validationfields-document
package to fix server-side validation
I have updated this pull request and rebased each of the changes. Thanks again for this @marekryb, and I have the same conclusion, this may not resolve every situation for now, but, we should be nearer to that with this pull request. |
c7a88fb
to
f96e4c4
Compare
fields-document
package to fix server-side validation@keystone-6/fields-document
package breaking when compiling in SSR environments
Thank you for pushing this forward @dcousens. I made this PR when trying to upgrade some older project to nextjs with RSC, but priorities changed etc... Sorry for no updates. This should solve the problem when using stock editor (yay). However last time I tried, it still breaks when using custom components. As I remember my conclusion at that time was that the interface for custom components needs to be changed to make it work as well. Something to look at later time perhaps. |
This attempts to fix #8717 (Attempted to call
validateAndNormalizeDocument()
from the server).As stated in #8403 (comment) that made a workaround by adding
use client
clauses:In principle, this PR splits bunch of
.tsx
files into two separate ones. One for react-related (client-side) code and second one for platform-agnostic code. I am keeping the original file for backwards compatibility.For example file:
packages/fields-document/src/DocumentEditor/insert-menu.tsx
has been split into:
packages/fields-document/src/DocumentEditor/insert-menu-model.ts
packages/fields-document/src/DocumentEditor/insert-menu-view.tsx
and the original file is now exporting above two:
External exports do not change, however internally, files that take part in validation process now import
-model.ts
files that are not importing disallowed hooks (useState
etc).There are no functional changes in the code apart from one in
packages/fields-document/src/DocumentEditor/utils-model.ts::insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading
. I will write about this one in the comment below.It seems to work fine with my limited testing and all unit tests are passing. However I did not test this in some more advanced scenario and with custom components yet.
Please let me know whether this is something that you are willing to work on and eventually accept.