Skip to content

Commit

Permalink
Do not use KV for the manifest files
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Nov 16, 2023
1 parent 09a9ead commit 209032b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 79 deletions.
1 change: 0 additions & 1 deletion apps/cloudflare-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"watch:dev": "NODE_OPTIONS='--import=tsx --conditions=@mfng:internal' webpack --mode development --watch"
},
"dependencies": {
"@cloudflare/kv-asset-handler": "^0.3.0",
"@mfng/core": "*",
"@mfng/shared-app": "*",
"react": "0.0.0-experimental-8039e6d0b-20231026",
Expand Down
32 changes: 0 additions & 32 deletions apps/cloudflare-app/src/worker/get-json-from-kv.ts

This file was deleted.

47 changes: 11 additions & 36 deletions apps/cloudflare-app/src/worker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import {routerLocationAsyncLocalStorage} from '@mfng/core/router-location-async-local-storage';
import type {ServerManifest} from '@mfng/core/server/rsc';
import {createRscActionStream, createRscAppStream} from '@mfng/core/server/rsc';
import {createHtmlStream} from '@mfng/core/server/ssr';
import * as React from 'react';
import type {ClientManifest, SSRManifest} from 'react-server-dom-webpack';
import {App} from './app.js';
import type {EnvWithStaticContent, HandlerParams} from './get-json-from-kv.js';
import {getJsonFromKv} from './get-json-from-kv.js';

const handleGet: ExportedHandlerFetchHandler<EnvWithStaticContent> = async (
request,
env,
ctx,
) => {
const params: HandlerParams = {request, env, ctx};

const [reactClientManifest, reactSsrManifest, jsManifest, cssManifest] =
await Promise.all([
getJsonFromKv<ClientManifest>(
`client/react-client-manifest.json`,
params,
),
getJsonFromKv<SSRManifest>(`client/react-ssr-manifest.json`, params),
getJsonFromKv<Record<string, string>>(`client/js-manifest.json`, params),
getJsonFromKv<Record<string, string>>(`client/css-manifest.json`, params),
]);

import {
cssManifest,
jsManifest,
reactClientManifest,
reactServerManifest,
reactSsrManifest,
} from './manifests.js';

const handleGet: ExportedHandlerFetchHandler = async (request) => {
const {pathname, search} = new URL(request.url);

return routerLocationAsyncLocalStorage.run({pathname, search}, async () => {
Expand All @@ -51,11 +37,7 @@ const handleGet: ExportedHandlerFetchHandler<EnvWithStaticContent> = async (
});
};

const handlePost: ExportedHandlerFetchHandler<EnvWithStaticContent> = async (
request,
env,
ctx,
) => {
const handlePost: ExportedHandlerFetchHandler = async (request) => {
const serverReferenceId = request.headers.get(`x-rsc-action`);

if (!serverReferenceId) {
Expand All @@ -70,13 +52,6 @@ const handlePost: ExportedHandlerFetchHandler<EnvWithStaticContent> = async (
? request.formData()
: request.text());

const params: HandlerParams = {request, env, ctx};

const [reactClientManifest, reactServerManifest] = await Promise.all([
getJsonFromKv<ClientManifest>(`client/react-client-manifest.json`, params),
getJsonFromKv<ServerManifest>(`react-server-manifest.json`, params),
]);

const rscActionStream = await createRscActionStream({
body,
serverReferenceId,
Expand All @@ -93,7 +68,7 @@ const handlePost: ExportedHandlerFetchHandler<EnvWithStaticContent> = async (
});
};

const handler: ExportedHandler<EnvWithStaticContent> = {
const handler: ExportedHandler = {
async fetch(request, env, ctx) {
switch (request.method) {
case `GET`:
Expand Down
13 changes: 13 additions & 0 deletions apps/cloudflare-app/src/worker/manifests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-nocheck
/* eslint-disable @typescript-eslint/no-require-imports,import/no-commonjs */

// These json imports will be preserved by webpack, and then bundled by wrangler
// into the final worker bundle. This needs to be done in this way,
// because most of the manifests are only available after the client bundle has
// been created, at which point webpack has already emitted the server bundle.

export const reactServerManifest = require(/* webpackIgnore: true */ `./react-server-manifest.json`);
export const reactClientManifest = require(/* webpackIgnore: true */ `./client/react-client-manifest.json`);
export const reactSsrManifest = require(/* webpackIgnore: true */ `./client/react-ssr-manifest.json`);
export const cssManifest = require(/* webpackIgnore: true */ `./client/css-manifest.json`);
export const jsManifest = require(/* webpackIgnore: true */ `./client/js-manifest.json`);
2 changes: 1 addition & 1 deletion apps/cloudflare-app/src/worker/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ watch_dir = []

[assets]
bucket = "../../dist"
include = ["client", "react-server-manifest.json"]
include = ["client"]
serve_single_page_app = true
10 changes: 1 addition & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 209032b

Please sign in to comment.