Skip to content

Commit b9e8eab

Browse files
authored
SPA Mode (#8457)
1 parent 8def758 commit b9e8eab

File tree

15 files changed

+574
-20
lines changed

15 files changed

+574
-20
lines changed

integration/compiler-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ test.describe("compiler", () => {
252252
);
253253

254254
let routeModule = await fixture.getBrowserAsset(
255-
fixture.build.assets.routes["routes/built-ins"].module
255+
fixture.build!.assets.routes["routes/built-ins"].module
256256
);
257257
// does not include `import bla from "node:path"` in the output bundle
258258
expect(routeModule).not.toMatch(/from\s*"path/);
@@ -271,7 +271,7 @@ test.describe("compiler", () => {
271271
);
272272

273273
let routeModule = await fixture.getBrowserAsset(
274-
fixture.build.assets.routes["routes/built-ins-polyfill"].module
274+
fixture.build!.assets.routes["routes/built-ins-polyfill"].module
275275
);
276276
// does not include `import bla from "node:path"` in the output bundle
277277
expect(routeModule).not.toMatch(/from\s*"path/);

integration/flat-routes-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test.describe("flat routes", () => {
160160
}
161161

162162
test("allows ignoredRouteFiles to be configured", async () => {
163-
let routeIds = Object.keys(fixture.build.routes);
163+
let routeIds = Object.keys(fixture.build!.routes);
164164

165165
expect(routeIds).not.toContain(IGNORED_ROUTE);
166166
});

integration/helpers/create-fixture.ts

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
5151
compiler === "vite" ? "build/server/index.js" : "build/index.js"
5252
)
5353
).href;
54+
55+
let getBrowserAsset = async (asset: string) => {
56+
return fse.readFile(
57+
path.join(projectDir, "public", asset.replace(/^\//, "")),
58+
"utf8"
59+
);
60+
};
61+
62+
let isSpaMode =
63+
compiler === "vite" &&
64+
fse.existsSync(path.join(projectDir, "build/client/index.html"));
65+
66+
if (isSpaMode) {
67+
return {
68+
projectDir,
69+
build: null,
70+
isSpaMode,
71+
compiler,
72+
requestDocument: () => {
73+
throw new Error("Cannot requestDocument in SPA Mode tests");
74+
},
75+
requestData: () => {
76+
throw new Error("Cannot requestData in SPA Mode tests");
77+
},
78+
postDocument: () => {
79+
throw new Error("Cannot postDocument in SPA Mode tests");
80+
},
81+
getBrowserAsset,
82+
useRemixServe: init.useRemixServe,
83+
};
84+
}
85+
5486
let app: ServerBuild = await import(buildPath);
5587
let handler = createRequestHandler(app, mode || ServerMode.Production);
5688

@@ -89,16 +121,10 @@ export async function createFixture(init: FixtureInit, mode?: ServerMode) {
89121
});
90122
};
91123

92-
let getBrowserAsset = async (asset: string) => {
93-
return fse.readFile(
94-
path.join(projectDir, "public", asset.replace(/^\//, "")),
95-
"utf8"
96-
);
97-
};
98-
99124
return {
100125
projectDir,
101126
build: app,
127+
isSpaMode,
102128
compiler,
103129
requestDocument,
104130
requestData,
@@ -175,6 +201,22 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
175201
});
176202
}
177203

204+
if (fixture.isSpaMode) {
205+
return new Promise(async (accept) => {
206+
let port = await getPort();
207+
let app = express();
208+
app.use(express.static(path.join(fixture.projectDir, "build/client")));
209+
app.get("*", (_, res, next) =>
210+
res.sendFile(
211+
path.join(process.cwd(), "build/client/index.html"),
212+
next
213+
)
214+
);
215+
let server = app.listen(port);
216+
accept({ stop: server.close.bind(server), port });
217+
});
218+
}
219+
178220
return new Promise(async (accept) => {
179221
let port = await getPort();
180222
let app = express();
@@ -281,7 +323,7 @@ export async function createFixtureProject(
281323
at the same time, unless the \`remix.config.js\` file contains a reference
282324
to the \`global.INJECTED_FIXTURE_REMIX_CONFIG\` placeholder so it can
283325
accept the injected config values. Either move all config values into
284-
\`remix.config.js\` file, or spread the injected config,
326+
\`remix.config.js\` file, or spread the injected config,
285327
e.g. \`export default { ...global.INJECTED_FIXTURE_REMIX_CONFIG }\`.
286328
`);
287329
}

0 commit comments

Comments
 (0)