-
Notifications
You must be signed in to change notification settings - Fork 56
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
New survey page based on Next.js v13 using the app router and server actions #1756
New survey page based on Next.js v13 using the app router and server actions #1756
Conversation
Nice. The playwright failures here make sense. It's the result of combining the new playwright tests we wrote at code camp with the server action version of the survey form. |
b723dd9
to
5459f24
Compare
First little burst of activity since the hackathon produced 5459f24. The context here is I'm trying to get the survey page playwright tests green, and the executive summary is that this commit gets 2/5 of them green and then skips the remaining three. More details below.
|
92e0d10 gets the My first iteration of the app router thing here was actually mega sloppy about the server component / client component boundary. Now there's a clear & coherent boundary where the Tidying up that boundary line was enough to get this test passing. |
6964e23 has done two things: gotten the
Bit of a two steps forward one step back commit given the number of new playwright test failures it introduces and the worrying dependency on canary versions of key dependencies. But! BUT! We now finally have a decently clear view here of how it'll probably look to write this kind of code at Zetkin a little while in the future once all this bleeding edge stuff goes mainstream. And god help me I think I actually like it! |
a61b925
to
0175e2f
Compare
6964e23
to
be504a9
Compare
I'm just having a look at the preview deployment of this, and I'm missing the "What is this question?" question that should have two options. Are multi-choice questions not implemented? Or maybe it's because there is no What's being rendered on the previewThe API response for this survey{
"data" : {
"access" : "open",
"allow_anonymous" : true,
"callers_only" : false,
"campaign" : null,
"elements" : [
{
"hidden" : false,
"id" : 1,
"question" : {
"description" : "Answer whatever",
"options" : [
{
"id" : 1,
"text" : "Option 1"
},
{
"id" : 2,
"text" : "Option 2"
}
],
"question" : "What is this question?",
"required" : false,
"response_config" : {},
"response_type" : "options"
},
"type" : "question"
},
{
"hidden" : false,
"id" : 2,
"text_block" : {
"content" : "With some instructions",
"header" : "This is a text block"
},
"type" : "text"
},
{
"hidden" : false,
"id" : 3,
"question" : {
"description" : null,
"question" : "Is this a free text question?",
"required" : false,
"response_config" : {
"multiline" : true
},
"response_type" : "text"
},
"type" : "question"
}
],
"expires" : null,
"id" : 1,
"info_text" : "This is a survey",
"org_access" : "sameorg",
"organization" : {
"id" : 1,
"title" : "My Organization"
},
"published" : "2024-02-22T06:16:19.016317",
"signature" : "allow_anonymous",
"title" : "A very open survey"
}
} |
Good spot, I’ll get that sorted this evening. Will also have another look at the playwright thing. The canary version of react-dom is what’s behind all the failing tests so I’m keeping an eye open for new versions in case one fixes that. |
Localization for link and descriptions to Swedish
copyText={`${location.protocol}//${location.host}/o/${orgId}/surveys/${surveyId}`} | ||
> | ||
{`${process.env.NEXT_PUBLIC_ZETKIN_APP_DOMAIN}/o/${orgId}/surveys/${surveyId}`} | ||
{`${location.protocol}//${location.host}/o/${orgId}/surveys/${surveyId}`} |
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.
The orgId
in both of these places should be survey.organization.id
(which may or may not be the organization that we're currently working within). You should be able to get it using useSurvey()
.
See #1941 for related changes (but we refrained from making changes to the URL there to avoid merge conflicts).
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 looks familiar!!! Did #1936 turn out to be the tip of the iceberg? I'll get this sorted right away.
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.
…ter-and-server-action There was a merge conflict here in SurveyURLCard. In e25252a the URL generation had been changed in main, replacing process.env.NEXT_PUBLIC_ZETKIN_APP_DOMAIN with env.vars.ZETKIN_APP_DOMAIN. That's a change that makes sense in the context of the main branch. This branch removes that variable entirely because it moves the survey URL to the same host. So not a tough conflict to resolve.
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.
I think it's becoming time to merge this. I have some minor questions below, and I think it would be nice to merge main one last time after EOP tomorrow. Then let's get it merged fully!
When you merge |
The latest commit in this branch now has a broken build. I've fixed the linter errors and removed the commented-out code but there's a new problem. The Storybook fixes have introduced a new react-dom version and it's broken the
|
Before the Storybook fixes | After the Storybook fixes |
---|---|
|
|
It looks like this API has also changed in React since we first worked on this branch, which is fair enough given it's marked as experimental. If you look at the docs for useActionState
they say
In earlier React Canary versions, this API was part of React DOM and called useFormState.
Okay then, having now looked deeper into this, it seems to be a change they've shipped in React 19. So for as long as we're on 18 this doesn't affect us. This pull request has been open too long to contemplate bundling a React version upgrade into it along with everything else, I think. So I'm going to sit and get this working again with a canary version of React 18.
Confirmed that the import still actually works fine and that the type error is a false alarm. I think my earlier theory about this being related to the duplicate react-dom versions was wrong. This seems like it might be related to the TypeScript upgrade instead. I made the following change. import { Box } from '@mui/material';
import { FC } from 'react';
+// @ts-expect-error Erroneous `Module '"react-dom"' has no exported member 'useFormState'`
import { useFormState } from 'react-dom'; Then tested submitting a survey, and it worked fine. The playwright tests all pass. I'm going to push this so that we have a green build here. From there we can do whatever. |
Finally cracked the mystery of the TypeScript error! It's a known eslint-plugin-import bug where it moves imports but leaves comments behind. Zooming out the diff in the screenshot below, you can see the removal in red at the bottom, the addition in green at the top, and the comment left behind in the old location at the bottom. Nice to have this one tidied up. At this point I'm happy this branch is cleaned up and ready @richardolsson. |
…ter-and-server-action
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.
Ok, the time is finally hear! Let's get this merged and included in the next release.
Amazing work on this over the 10-or-so month lifespan of this project, @henrycatalinismith! 🙌
omfg 😂 |
Combining all our work from #1636, #1719 and #1738. Targeting the branch for #1719 as the code changes here depend on merging the Next v13 upgrade to
main
. Once #1719 ships we can update the base branch of this PR tomain
.