Skip to content
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

NoJS mode is broken: initFromFlash cookie does not populate submission props #449

Closed
frenzzy opened this issue Jun 17, 2024 · 1 comment
Closed

Comments

@frenzzy
Copy link

frenzzy commented Jun 17, 2024

Describe the bug

When user submits a form in NOJS mode, SolidStart sets a "flash=" cookie and redirects back to the same url:

Screenshot 2024-06-17 at 1 44 34 PM

During SSR it executes initFromFlash logic and extracts submission info from cookie:

const submissions = createSignal<Submission<any, any>[]>(isServer ? initFromFlash() : []);

But unfortunately it does not become available in useSubmission hook:

router.submissions[0]().filter(s => s.url === fn.toString() && (!filter || filter(s.input)))

Probably something is broken with reactivity or context on server-side...

Your Example Website or App

Please update demo link to fork using SolidStart 1.0

Steps to Reproduce the Bug or Issue

  1. Create a new route file, for example src/routes/demo.tsx:
import { action, useSubmission } from '@solidjs/router'
import { getRequestEvent } from 'solid-js/web'

const myAction = action(async (formData: FormData) => {
  'use server'
  const value = String(formData.get('test'))
  await new Promise((resolve) => setTimeout(resolve, 1000))
  return `It works! ${value}`
}, 'myAction')

export default function RouteExample() {
  const submission = useSubmission(myAction)
  console.log(getRequestEvent()?.router?.submission?.url)    // _server?id=%2FUsers%2Fsite%2Fy%2Fsrc%2Froutes%2Fx.tsx%3Fpick%3Ddefault%26pick%3D%24css&name=%24%24function0
  console.log(getRequestEvent()?.router?.submission?.result) // 'It works! 123'
  console.log(submission.result)                             // undefined
  console.log(submission.url)                                // undefined
  return (
    <form action={myAction} method="post">
      <input
        name="test"
        value={String(submission.input?.[0]?.get('test') || '123')}
      />
      <button type="submit">Submit</button>
      <p>Result: {submission.result}</p>
    </form>
  )
}
  1. Disable JS in your browser, open the page and submit the form
  2. See server console

Expected behavior

Last submission data is available during SSR

Screenshots or Videos

No response

Platform

  • "@solidjs/router": "^0.13.5",
  • "@solidjs/start": "^1.0.1",

Additional context

Link to the thread in Discord with additional details, see also solidjs/solid-start#1552

@ryansolid
Copy link
Member

ryansolid commented Jun 18, 2024

I think this is a regression from a recent change in the router. Thanks for reporting.

EDIT: No I was wrong.. a fix for this(solidjs/solid-start#1552) actually broke the proper behavior. That issue needs to be fixed a different way.

EDIT 2: It's both. Solid Router update to 0.13.4 broke something as well. It appears that this pull request although it was merged earlier didn't come out until 0.13.4 and is the cause of the break: #405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants