solidjs / solid-router

A universal router for Solid inspired by Ember and React Router
MIT License
1.14k stars 146 forks source link

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

Closed frenzzy closed 3 months ago

frenzzy commented 3 months ago

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: https://github.com/solidjs/solid-router/blob/10b7d8ce03d3aef11074199800bb78ea5fc1b426/src/routing.ts#L341

But unfortunately it does not become available in useSubmission hook: https://github.com/solidjs/solid-router/blob/10b7d8ce03d3aef11074199800bb78ea5fc1b426/src/data/action.ts#L27

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 (

Result: {submission.result}

) }


2. Disable JS in your browser, open the page and submit the form
3. 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](https://discord.com/channels/722131463138705510/910635844119982080/1252153969321443358), see also https://github.com/solidjs/solid-start/pull/1552
ryansolid commented 3 months ago

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(https://github.com/solidjs/solid-start/pull/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: https://github.com/solidjs/solid-router/pull/405