-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: HTML streaming in Podium #507
Open
digitalsadhu
wants to merge
16
commits into
main
Choose a base branch
from
prototype_html_streaming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
80b02c6
feat: html streaming
digitalsadhu 2c2b292
refactor: remove the need to rewrite html templates
digitalsadhu fa708b2
chore: remove console logs and add comments
digitalsadhu 5b91cb7
chore: add simple server example
digitalsadhu 4618d55
test: fix test snapshot
digitalsadhu 5a575a8
test: set snapshot back again
digitalsadhu 858a50f
chore: ignore type errors
digitalsadhu ada6812
docs: update docs and add tests
digitalsadhu b75d0d4
chore: update @podium/test-utils
digitalsadhu ef3bcf9
Merge branch 'main' into prototype_html_streaming
digitalsadhu 651eee0
refactor: drop early hints, use link header assets
digitalsadhu 7a9a164
refactor(examples): rework examples to match latest podium
digitalsadhu d954732
feat: wait for assets inside podiumStream
digitalsadhu fa559f9
chore: update examples
digitalsadhu 9d69703
chore: set content type
digitalsadhu 4a7b87f
test: refactor and expand streaming tests
digitalsadhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,61 @@ | ||
import Podlet from '@podium/podlet'; | ||
import express from 'express'; | ||
|
||
const podlet = new Podlet({ | ||
name: 'content-podlet', | ||
version: Date.now().toString(), | ||
pathname: '/', | ||
useShadowDOM: true, | ||
}); | ||
|
||
podlet.css({ value: 'http://localhost:6103/css', strategy: 'shadow-dom' }); | ||
|
||
const app = express(); | ||
|
||
app.use(podlet.middleware()); | ||
|
||
app.get('/manifest.json', (req, res) => { | ||
res.send(podlet); | ||
}); | ||
|
||
app.get('/css', (req, res) => { | ||
res.set('Content-Type', 'text/css'); | ||
res.send(` | ||
* { | ||
box-sizing: border-box; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
.content { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
font-family: Verdana, serif; | ||
font-weight: 400; | ||
font-style: normal; | ||
} | ||
h1 { | ||
color: #136C72; | ||
} | ||
`); | ||
}); | ||
|
||
app.get('/', async (req, res) => { | ||
res.set('Content-Type', 'text/html'); | ||
res.sendHeaders(); | ||
|
||
await new Promise((res) => setTimeout(res, 2200)); | ||
|
||
res.podiumSend(` | ||
<section class="content"> | ||
<h1>Podlets fetched and composed, on demand, just for you</h1> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p> | ||
</section> | ||
`); | ||
Comment on lines
+45
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The layout examples have some inline documentation explaining the different parts. It would be nice to have something similar for at least one of the podlets, or in a separate README. If it's covered in the podlet-repo, perhaps link to docs there? |
||
}); | ||
|
||
app.listen(6103, () => { | ||
console.log(`content podlet server running at http://localhost:6103`); | ||
}); |
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,83 @@ | ||
import Podlet from '@podium/podlet'; | ||
import express from 'express'; | ||
|
||
const podlet = new Podlet({ | ||
name: 'footer-podlet', | ||
version: Date.now().toString(), | ||
pathname: '/', | ||
useShadowDOM: true, | ||
}); | ||
|
||
podlet.css({ value: 'http://localhost:6104/css', strategy: 'shadow-dom' }); | ||
|
||
const app = express(); | ||
|
||
app.use(podlet.middleware()); | ||
|
||
app.get('/manifest.json', (req, res) => { | ||
res.send(podlet); | ||
}); | ||
|
||
app.get('/css', (req, res) => { | ||
res.set('Content-Type', 'text/css'); | ||
res.send(` | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
footer { | ||
width: 100%; | ||
background-color: #23424A; | ||
color: white; | ||
padding: 1em 0 6em 0; | ||
font-family: Verdana, serif; | ||
font-weight: 400; | ||
font-style: normal; | ||
} | ||
.container { | ||
width: 75%; | ||
max-width: 1000px; | ||
margin: 0 auto; | ||
} | ||
ul { | ||
list-style: none; | ||
display: flex; | ||
justify-content: space-evenly; | ||
align-items: center; | ||
} | ||
a { | ||
text-transform: upper-case; | ||
color: white; | ||
text-decoration: none; | ||
} | ||
a:hover, a:active { | ||
text-decoration: underline; | ||
} | ||
`); | ||
}); | ||
|
||
app.get('/', async (req, res) => { | ||
res.set('Content-Type', 'text/html'); | ||
res.sendHeaders(); | ||
|
||
await new Promise((res) => setTimeout(res, 100)); | ||
|
||
res.podiumSend(` | ||
<footer> | ||
<div class="container"> | ||
<ul> | ||
<li><a href="#">Home</a></li> | ||
<li><a href="#">About</a></li> | ||
<li><a href="#">Contact</a></li> | ||
<li><a href="#">Sign in</a></li> | ||
<li><a href="#">Sign up</a></li> | ||
</ul> | ||
</div> | ||
</footer> | ||
`); | ||
}); | ||
|
||
app.listen(6104, () => { | ||
console.log(`footer podlet server running at http://localhost:6104`); | ||
}); |
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,97 @@ | ||
import Podlet from '@podium/podlet'; | ||
import express from 'express'; | ||
|
||
const podlet = new Podlet({ | ||
name: 'header-podlet', | ||
version: Date.now().toString(), | ||
pathname: '/', | ||
useShadowDOM: true, | ||
}); | ||
|
||
podlet.css({ value: 'http://localhost:6101/css', strategy: 'shadow-dom' }); | ||
|
||
const app = express(); | ||
|
||
app.use(podlet.middleware()); | ||
|
||
app.get('/manifest.json', (req, res) => { | ||
res.send(podlet); | ||
}); | ||
|
||
app.get('/css', (req, res) => { | ||
res.set('Content-Type', 'text/css'); | ||
res.send(` | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
header { | ||
width: 100%; | ||
padding: 6em 0; | ||
background-color: #23424A; | ||
font-size: 1.5rem; | ||
font-family: "Verdana", sans-serif; | ||
font-weight: 400; | ||
font-style: normal; | ||
color: white; | ||
} | ||
h1 { | ||
font-size: 3rem; | ||
color: white; | ||
font-family: "Verdana", sans-serif; | ||
font-weight: 900; | ||
font-style: normal; | ||
} | ||
.container { | ||
width: 75%; | ||
max-width: 1000px; | ||
margin: 0 auto; | ||
} | ||
.inner-container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
} | ||
.button { | ||
color: black; | ||
background-color: #38CFD9; | ||
padding: 0.5em 1.25em; | ||
border-radius: 1em; | ||
text-decoration: none; | ||
width: fit-content; | ||
} | ||
.button:hover, .button:active { | ||
text-decoration: underline; | ||
width: fit-content; | ||
} | ||
@media (min-width: 800px) { | ||
.inner-container { | ||
width: 70%; | ||
} | ||
} | ||
`); | ||
}); | ||
|
||
app.get('/', async (req, res) => { | ||
res.set('Content-Type', 'text/html'); | ||
res.sendHeaders(); | ||
|
||
await new Promise((res) => setTimeout(res, 100)); | ||
|
||
res.podiumSend(` | ||
<header> | ||
<div class="container"> | ||
<div class="inner-container"> | ||
<h1>Podium layouts can be composed using streaming</h1> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p> | ||
<a href="#" class="button">I want to learn</a> | ||
</div> | ||
</div> | ||
</header> | ||
`); | ||
}); | ||
|
||
app.listen(6101, () => { | ||
console.log(`header podlet server running at http://localhost:6101`); | ||
}); |
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,76 @@ | ||
import Podlet from '@podium/podlet'; | ||
import express from 'express'; | ||
|
||
const podlet = new Podlet({ | ||
name: 'menu-podlet', | ||
version: Date.now().toString(), | ||
pathname: '/', | ||
useShadowDOM: true, | ||
}); | ||
|
||
podlet.css({ value: 'http://localhost:6102/css', strategy: 'shadow-dom' }); | ||
|
||
const app = express(); | ||
|
||
app.use(podlet.middleware()); | ||
|
||
app.get('/manifest.json', (req, res) => { | ||
res.send(podlet); | ||
}); | ||
|
||
app.get('/css', (req, res) => { | ||
res.set('Content-Type', 'text/css'); | ||
res.send(` | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
.menu { | ||
width: 100%; | ||
background-color: #136C72; | ||
padding: 1em 0; | ||
font-family: Verdana, serif; | ||
font-weight: 400; | ||
font-style: normal; | ||
} | ||
.menu ul { | ||
list-style: none; | ||
display: flex; | ||
justify-content: space-evenly; | ||
align-items: center; | ||
} | ||
a { | ||
text-transform: upper-case; | ||
color: white; | ||
text-decoration: none; | ||
} | ||
a:hover, a:active { | ||
text-decoration: underline; | ||
} | ||
`); | ||
}); | ||
|
||
app.get('/', async (req, res) => { | ||
res.set('Content-Type', 'text/html'); | ||
res.sendHeaders(); | ||
|
||
// imagine this is your slow database call | ||
await new Promise((res) => setTimeout(res, 100)); | ||
|
||
res.podiumSend(` | ||
<nav class="menu"> | ||
<ul> | ||
<li><a href="#">Home</a></li> | ||
<li><a href="#">About</a></li> | ||
<li><a href="#">Contact</a></li> | ||
<li><a href="#">Sign in</a></li> | ||
<li><a href="#">Sign up</a></li> | ||
</ul> | ||
</nav> | ||
`); | ||
}); | ||
|
||
app.listen(6102, () => { | ||
console.log(`menu podlet server running at http://localhost:6102`); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be an options object so we can add to it without causing a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there are any breaking changes to worry about here. Did you spot something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not now, I'm thinking if we want to add stuff in the future.