`query()` copies a `respond()` envelope's `Content-Type: application/json` onto the SSR document response
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend-api-design, web-dev
Hướng nghiên cứu
Start in @solidjs/router/dist/data/query.js, around handleResponse at lines 248-263, and reproduce the issue with the provided Vite build and curl commands. Trace how respond() headers reach the SSR document response, then verify that envelope representation headers no longer replace text/html while needed redirect-related headers still work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Versions
- @solidjs/router 2.0.0-next.30 and 2.0.0-next.31
- @solidjs/web 2.0.0-rc.11, solid-js 2.0.0-rc.11
- @solidjs/vite-plugin 3.0.0-next.46 (start mode,
ssr: true,serverFunctions: true, defaultrenderMode) - vite 8.3.1, Node 24.20.0
Reproduction
// vite.config.ts
import { defineConfig } from 'vite'
import solid from '@solidjs/vite-plugin'
export default defineConfig({
plugins: [solid({ start: { node: true }, ssr: true, serverFunctions: true })]
})
// src/data.ts
import { respond } from '@solidjs/web'
export async function thrownRead(): Promise<never> {
'use server'
await new Promise(resolve => setTimeout(resolve, 20))
throw respond({ message: 'conflict' }, { status: 409 })
}
export async function returnedRead() {
'use server'
await new Promise(resolve => setTimeout(resolve, 20))
return respond({ message: 'accepted' }, { status: 202 })
}
// src/pages.tsx
import { createMemo } from 'solid-js'
import { query } from '@solidjs/router'
import { returnedRead, thrownRead } from './data'
const getThrown = query(thrownRead, 'thrown')
const getReturned = query(returnedRead, 'returned')
export function Thrown() {
const data = createMemo(() => getThrown())
return <p>{String(data())}</p>
}
export function Returned() {
const data = createMemo(() => getReturned())
return <p>{data().message}</p>
}
export function Home() {
return <p>home</p>
}
// src/router.ts
import { createRouter } from '@solidjs/router'
import { Home, Returned, Thrown } from './pages'
export const Router = createRouter({
routes: [
{ path: '/', component: Home },
{ path: '/thrown', component: Thrown },
{ path: '/returned', component: Returned }
]
})
// src/App.tsx
import { Errored } from 'solid-js'
import { httpStatus } from '@solidjs/web'
import { Router } from './router'
function Failed() {
httpStatus(500)
return <p>failed</p>
}
export default function App() {
return (
<Errored fallback={() => <Failed />}>
<Router>{props => props.children}</Router>
</Errored>
)
}
vite build
PORT=4399 node dist/server/node.js
curl -sS -D - -o /dev/null http://127.0.0.1:4399/
curl -sS -D - -o /dev/null http://127.0.0.1:4399/thrown
curl -sS -D - -o /dev/null http://127.0.0.1:4399/returned
Expected
Both documents keep content-type: text/html; charset=utf-8, like /. The envelope's Content-Type describes the envelope's own JSON body; it is not metadata for the page that read the query.
Actual
/ HTTP/1.1 200 OK content-type: text/html; charset=utf-8
/thrown HTTP/1.1 500 Internal Server Error content-type: application/json
/returned HTTP/1.1 200 OK content-type: application/json
The body of both is the HTML document, so browsers render it as text. The server also logs twice:
[LATE_HEADER_WRITE] Response header write dropped: headers.set("content-type") ran after the response head was sent. Write headers before the shell flushes (or before the handler returns).
Same result with router 2.0.0-next.31.
Analysis (published files)
respond()gives the carried ResponseContent-Type: application/json(@solidjs/web/dist/server.js,respond, line 520 in rc.11).- A server function called directly during SSR runs with a shallow copy of the page event, so
getRequestEvent().responseinside the read is the page's response stub (@solidjs/web/server-functions/dist/server.js, around lines 1469-1477 in rc.11). query()'shandleResponseunwraps the envelope and then copies every header ofenvelope.responseontogetRequestEvent().response(@solidjs/router/dist/data/query.js, lines 248-263 in next.30). For a returned or thrownrespond(), that includescontent-type.- Copies that run before the shell flush end up on the document; later reads hit the committed stub and are dropped with
[LATE_HEADER_WRITE].
The blanket header copy comes from #525 (for Set-Cookie on redirects). The envelope unwrap added in front of it later (c9f8c25a, "Adopt the core server-function protocol from @solidjs/web") now routes the envelope's body headers into it. The next branch at the 2.0.0-next.31 release still copies every header without a filter.
Possible fix
In handleResponse, skip representation headers (content-type, content-length, content-encoding, transfer-encoding) when copying from a Response or envelope onto e.response, and consider not writing to e.response once it is committed.
Related
- #525: introduced the header copy in
handleResponse. - #603 / #606: same
handleResponse, redirect carrier only; the header copy is unchanged. - solidjs/solid#3433: added the
[LATE_HEADER_WRITE]diagnostic. - solidjs/solid-start#2025: a different late header write through
query()+ redirect during SSR (closed as not planned).
- Ngôn ngữ chính
- TypeScript
- Star
- 1.3k
- Fork
- 180
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của solidjs/solid-router
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 50/100
solidjs/solid-router#625 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Query enumeration recomputes on pathname/hash-only navigation with unchanged search (Solid 2)Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
solidjs/solid-router#624 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
<A> costs ~6us of server CPU per instance during SSR (20x a plain <a>), mostly mergeProps/splitPropsĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
solidjs/solid-router#583 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
solidjs/solid-router#569 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
solidjs/solid-router#518 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của solidjs/solid-router
Issue tương tự
-
needs:triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-discovered
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
jessepollak/home#1627 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent-canvas bug llm priority:low ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OpenHands/OpenHands#17806 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
radius-project/ai-extensions#923 ·
Maintainer thường phản hồi trong vòng 1 ngày