flamefront 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/action-client.ts +29 -3
- package/src/action.ts +9 -0
- package/src/vite.ts +14 -3
package/package.json
CHANGED
package/src/action-client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as devalue from "devalue"
|
|
2
2
|
import { data } from "@octanejs/remix-router"
|
|
3
3
|
import {
|
|
4
|
+
actionRedirectStatusHeader,
|
|
4
5
|
actionProtocolEnvelope,
|
|
5
6
|
actionResponseInit,
|
|
6
7
|
type ActionEnvelope,
|
|
@@ -45,6 +46,19 @@ function isRedirect(response: Response): boolean {
|
|
|
45
46
|
return response.status >= 300 && response.status < 400
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
function transportedRedirect(response: Response): Response | undefined {
|
|
50
|
+
const status = Number(response.headers.get(actionRedirectStatusHeader))
|
|
51
|
+
|
|
52
|
+
if (!Number.isInteger(status) || status < 300 || status >= 400) {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const headers = new Headers(response.headers)
|
|
57
|
+
|
|
58
|
+
headers.delete(actionRedirectStatusHeader)
|
|
59
|
+
return new Response(null, { status, headers })
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
function headersFromEnvelope(envelope: ActionEnvelope): Headers | undefined {
|
|
49
63
|
return envelope.headers.length > 0
|
|
50
64
|
? new Headers(
|
|
@@ -83,6 +97,14 @@ async function decodeActionResponse(
|
|
|
83
97
|
response: Response,
|
|
84
98
|
options: ActionRequestOptions,
|
|
85
99
|
): Promise<unknown> {
|
|
100
|
+
const redirect = transportedRedirect(response)
|
|
101
|
+
|
|
102
|
+
if (redirect) {
|
|
103
|
+
invalidateRouteDataCache()
|
|
104
|
+
invalidateRouteFragments()
|
|
105
|
+
throw redirect
|
|
106
|
+
}
|
|
107
|
+
|
|
86
108
|
if (isRedirect(response)) {
|
|
87
109
|
invalidateRouteDataCache()
|
|
88
110
|
invalidateRouteFragments()
|
|
@@ -157,7 +179,6 @@ export function createActionProxy<
|
|
|
157
179
|
const response = await globalThis.fetch(endpoint, {
|
|
158
180
|
method: "POST",
|
|
159
181
|
credentials: "same-origin",
|
|
160
|
-
redirect: "manual",
|
|
161
182
|
headers: {
|
|
162
183
|
"Content-Type": "application/vnd.flamefront.action+devalue",
|
|
163
184
|
Accept: "application/vnd.flamefront.action+devalue",
|
|
@@ -178,8 +199,13 @@ export async function submitRouteAction(
|
|
|
178
199
|
|
|
179
200
|
url.searchParams.set("__flamefront_action", "1")
|
|
180
201
|
const source = request.clone()
|
|
181
|
-
const
|
|
182
|
-
|
|
202
|
+
const actionRequest = new Request(url, {
|
|
203
|
+
method: source.method,
|
|
204
|
+
headers: source.headers,
|
|
205
|
+
body: await source.blob(),
|
|
206
|
+
signal: source.signal,
|
|
207
|
+
})
|
|
208
|
+
const response = await globalThis.fetch(actionRequest, {
|
|
183
209
|
credentials: "same-origin",
|
|
184
210
|
})
|
|
185
211
|
|
package/src/action.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as devalue from "devalue"
|
|
2
2
|
|
|
3
|
+
export const actionRedirectStatusHeader = "X-Flamefront-Redirect-Status"
|
|
4
|
+
|
|
3
5
|
/** The structural value returned by the router's `data()` helper. */
|
|
4
6
|
export interface ActionDataWithResponseInit<Data = unknown> {
|
|
5
7
|
readonly type: "DataWithResponseInit"
|
|
@@ -339,6 +341,13 @@ function envelopeResponse(envelope: ActionEnvelope): Response {
|
|
|
339
341
|
/** Encode an action return value or error as a Fetch response. */
|
|
340
342
|
export function actionResultResponse(value: unknown): Response {
|
|
341
343
|
if (value instanceof Response) {
|
|
344
|
+
if (value.status >= 300 && value.status < 400) {
|
|
345
|
+
const headers = new Headers(value.headers)
|
|
346
|
+
|
|
347
|
+
headers.set(actionRedirectStatusHeader, String(value.status))
|
|
348
|
+
return new Response(null, { status: 204, headers })
|
|
349
|
+
}
|
|
350
|
+
|
|
342
351
|
return value
|
|
343
352
|
}
|
|
344
353
|
|
package/src/vite.ts
CHANGED
|
@@ -820,10 +820,15 @@ export function flamefront(options: FlamefrontOptions = {}) {
|
|
|
820
820
|
transformOptions?: TransformOptions,
|
|
821
821
|
) {
|
|
822
822
|
const context = this as Pick<PluginContext, "environment">
|
|
823
|
+
const moduleId = cleanModuleId(id)
|
|
824
|
+
|
|
825
|
+
if (moduleId.endsWith(".md") || moduleId.endsWith(".mdx")) {
|
|
826
|
+
return null
|
|
827
|
+
}
|
|
823
828
|
|
|
824
829
|
if (
|
|
825
830
|
isServerEnvironment(context, transformOptions) &&
|
|
826
|
-
!
|
|
831
|
+
!moduleId.endsWith(".tsrx") &&
|
|
827
832
|
source.includes("action") &&
|
|
828
833
|
/flamefront(?:\/server)?["']/.test(source)
|
|
829
834
|
) {
|
|
@@ -838,7 +843,7 @@ export function flamefront(options: FlamefrontOptions = {}) {
|
|
|
838
843
|
}
|
|
839
844
|
|
|
840
845
|
if (
|
|
841
|
-
!
|
|
846
|
+
!moduleId.endsWith(".tsrx") &&
|
|
842
847
|
source.includes("action") &&
|
|
843
848
|
/flamefront(?:\/server)?["']/.test(source)
|
|
844
849
|
) {
|
|
@@ -1134,7 +1139,13 @@ export function flamefront(options: FlamefrontOptions = {}) {
|
|
|
1134
1139
|
return null
|
|
1135
1140
|
}
|
|
1136
1141
|
|
|
1137
|
-
|
|
1142
|
+
const moduleId = cleanModuleId(id)
|
|
1143
|
+
|
|
1144
|
+
if (moduleId.endsWith(".md") || moduleId.endsWith(".mdx")) {
|
|
1145
|
+
return null
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
if (!(await loadRouteModuleIds()).has(moduleId)) {
|
|
1138
1149
|
return null
|
|
1139
1150
|
}
|
|
1140
1151
|
|