-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add store option for linked mode builds (#40)
* feat: add store option for ssr-client state preservation * fix: add test case * fix: update readme * fix: add store unit tests * fix: remove non-supported entries option * chore: add changeset
- Loading branch information
Showing
24 changed files
with
392 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@marko/vite": patch | ||
--- | ||
|
||
Add store option for linked mode builds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/__snapshots__/build.expected.loading.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: false Clicks: 0 | ||
</div> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/__snapshots__/build.expected.loading.1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 0 | ||
</div> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/__snapshots__/build.expected.step-0.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 1 | ||
</div> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/__snapshots__/dev.expected.loading.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: false Clicks: 0 | ||
</div> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/__snapshots__/dev.expected.loading.1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 0 | ||
</div> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/__snapshots__/dev.expected.step-0.0.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div | ||
id="implicit" | ||
> | ||
<div | ||
id="clickable" | ||
> | ||
Mounted: true Clicks: 1 | ||
</div> | ||
</div> |
33 changes: 33 additions & 0 deletions
33
src/__tests__/fixtures/isomorphic-memory-store/dev-server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// In dev we'll start a Vite dev server in middleware mode, | ||
// and forward requests to our http request handler. | ||
|
||
const { createServer } = require("vite"); | ||
const { join } = require("path"); | ||
const markoPlugin = require("../../..").default; | ||
|
||
module.exports = (async () => { | ||
const devServer = await createServer({ | ||
root: __dirname, | ||
appType: "custom", | ||
logLevel: "silent", | ||
plugins: [markoPlugin()], | ||
optimizeDeps: { force: true }, | ||
server: { | ||
middlewareMode: true, | ||
watch: { | ||
ignored: ["**/node_modules/**", "**/dist/**", "**/__snapshots__/**"], | ||
}, | ||
}, | ||
}); | ||
return devServer.middlewares.use(async (req, res, next) => { | ||
try { | ||
const { handler } = await devServer.ssrLoadModule( | ||
join(__dirname, "./src/index.js") | ||
); | ||
await handler(req, res, next); | ||
} catch (err) { | ||
devServer.ssrFixStacktrace(err); | ||
return next(err); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// In production, simply start up the http server. | ||
const path = require("path"); | ||
const { createServer } = require("http"); | ||
const serve = require("serve-handler"); | ||
const { handler } = require("./dist/index.mjs"); | ||
const serveOpts = { public: path.resolve(__dirname, "dist") }; | ||
module.exports = createServer(async (req, res) => { | ||
await handler(req, res); | ||
if (res.headersSent) return; | ||
await serve(req, res, serveOpts); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/__tests__/fixtures/isomorphic-memory-store/src/components/class-component.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class { | ||
onCreate() { | ||
this.state = { | ||
clickCount: 0, | ||
mounted: false | ||
}; | ||
} | ||
onMount() { | ||
this.state.mounted = true; | ||
} | ||
handleClick() { | ||
this.state.clickCount++; | ||
} | ||
} | ||
|
||
<div#clickable onClick("handleClick")> | ||
Mounted: ${state.mounted} | ||
Clicks: ${state.clickCount} | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/src/components/implicit-component.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
static { | ||
if (typeof window === "object") { | ||
document.body.firstElementChild.append("Loaded Implicit Component"); | ||
} | ||
} | ||
|
||
<div#implicit> | ||
<class-component/> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
src/__tests__/fixtures/isomorphic-memory-store/src/components/layout-component.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
static { | ||
if (typeof window === "object") { | ||
document.body.firstElementChild.append("Loaded Layout Component"); | ||
} | ||
} | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Hello World</title> | ||
</head> | ||
<body> | ||
<${input.renderBody}/> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import template from "./template.marko"; | ||
|
||
export function handler(req, res) { | ||
if (req.url === "/") { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "text/html; charset=utf-8"); | ||
template.render({}, res); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/src/template.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
style { | ||
div { color: green } | ||
} | ||
|
||
<layout-component> | ||
<div#app> | ||
<implicit-component/> | ||
</div> | ||
</layout-component> |
9 changes: 9 additions & 0 deletions
9
src/__tests__/fixtures/isomorphic-memory-store/test.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { MemoryStore, type Options } from "../../.."; | ||
|
||
export const ssr = true; | ||
export async function steps() { | ||
await page.click("#clickable"); | ||
} | ||
export const options: Options = { | ||
store: new MemoryStore(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.