Comments (25)
I'm not sure if I've mentioned the below before on a different thread, apologies if I have.
This may be out of scope, but I've been thinking if the naming, especially for the server API, was more focused around what stage
the render cycle was in.
// _default.server.page.ts
// Could redirect
export async function onRequest() {
// Send a redirect perhaps, unauthorized etc?
// Return nothing just continues with render?
}
export async function onResponse(renderResult: string, originalRequest: Request) {
// Could modify the HTML perhaps?
return renderResult.
}
export async function onBeforeRender({ contextProps, Page }) {
return {
contextProps: {
...contextProps,
foo: 'bar'
}
}
}
from vike.
@chrisvariety Yes the idea is to rename all contextProps
variables.
For example, renaming all contextProps
to renderContext
while also renaming addContextProps
to onBeforeRender
.
export async function onBeforeRender({ renderContext, Page }) {
return {
// Add stuff to `renderContext`
renderContext: {
foo: 'bar'
}
}
}
export async function render({ renderContext, Page }) {
// ...
}
from vike.
I'm leaning towards renaming addContextProps
to addPageContext
.
I do like the onBeforeRender
idea, but it's sightly misleading for people who use useClientRouter()
(with Client-side Routing, when the user navigates to a new page, the browser makes a server request and onBeforeRender()
is called while the render()
hook is not called: the new page is only rendered to the DOM and is not rendered to HTML).
Happy to be contradicted and discuss.
from vike.
@deckchairlabs Because it will conflict with other context
objects, e.g. https://github.com/brillout/wildcard-api. Imagine a framework built on top of vite-plugin-ssr and Wildcard API; it will be confusing to have several context
objects that mean different things.
from vike.
Got a new idea, I'm thinking to name it renderContext
.
The thing is that contextProps
lives only during rendering; the contextProps
object is created when a page rendering starts (it's actually the user that creates the object when he does await renderPage({ url, contextProps: {} })
and contextProps
is (usually) free for garbage collection after the page rendering is done.
renderContext
may sound weird at first but it might actually clarify things. I'll meditate about it.
from vike.
I see, how about something more event/hook based? onBeforeRender
// _default.server.page.ts
export async function onBeforeRender({ contextProps, Page }) {
return {
contextProps: {
...contextProps,
foo: 'bar'
}
}
}
from vike.
Interesting, I didn't think about this.
from vike.
@deckchairlabs I like your idea. I'll medidate about renaming addContextProps
to onBeforeRender
. And good point that it will make it natural to add further hooks shall the need arise.
from vike.
Think I'm fine with all the suggesting, thanks for pinging and asking 🙌
🤜🤛
from vike.
I'm going to rename
contextProps
topageContext
andaddContextProps
toaddPageContext
in the next couple of days.
Done and released in 0.1.0-beta.45
.
Stage hooks are still open for consideration at #71.
from vike.
This is the last breaking change before I release the first non-beta version.
I will provide scripts to ease migration, e.g. grep addContextProps | xargs sed -i 's/addContextProps/addSsrContext/g'
.
Let me know if you object with the new name ssrContext
pageContext
.
EDIT: Changed title from "Rename contextProps
to ssrContext
." to "Rename contextProps
to pageContext
.".
@deckchairlabs
@doeixd
@gryphonmyers
@chrisvariety
(@gryphonmyers I will take care of updating the PR and resolve merge confits.)
from vike.
cc @ozergul @alsyapukov @aral @CanRau @ruslankonev @naranjamecanica
from vike.
Hi!
doc here (https://github.com/brillout/vite-plugin-ssr) not true for boilerplate template.
How me get data from (https://swapi.dev/api/films/${movieId}/?format=json) by node-fetch and out Page as json. How many times knocking result only empty {} in browser (link /movies/1) How knew clearing mind truth? Big fans before
from vike.
@rulentor write me on Discord
from vike.
Why can't it just be simply context
?
from vike.
addContextProps
is just half of the story though, what are we calling it in function render({ Page, contextProps }: { Page: ReactComponent; contextProps: ContextProps }) { ... }
? It seems a little weird to rename to onBeforeRender
but still have the render function have contextProps
.
from vike.
This all sounds good, however I'm now even more confused by the prospect of doing client-side fetching as described in #52. If it's now renderContext
, how / why does the client have the ability to affect it when it's the server that does the rendering?
from vike.
I'm still pondering the renaming.
So far I like the renderContext
name as it makes it clearer that the renderContext
object lives only for the purpose of rendering.
I'm hesitating about onBeforeRender
precisely because, when using useClientRouter()
and when the user navigates to a new page, then it's somewhat confusing that the only thing called on the server is onBeforeRender
.
from vike.
From discord https://discord.com/channels/815937377888632913/815937377888632916/842824951350427688
pageContext
andgetPageContext
is what came to my mind. Since it is all about the page (no?).
My reply:
I like your idea, makes sense. It somewhat conflicts with
pageProps
but we can rename that as well.
from vike.
My current favorite is now pageContext
.
from vike.
I decided for pageContext
.
I'm still hesitating about the hook thing.
from vike.
I'm going to rename contextProps
to pageContext
and addContextProps
to addPageContext
in the next couple of days.
I'm still thinking about the stage-hook thing. I like it but I still need time to let the idea sink in. If anyone as more thoughts about stage-hooks, now is the time.
Looking forward to see what we come up with. Well designed stage-hooks could be a wonderful thing.
Opened a new ticket for it #71.
from vike.
I'm going to rename
contextProps
topageContext
andaddContextProps
toaddPageContext
in the next couple of days.I'm still thinking about the stage-hook thing. I like it but I still need time to let the idea sink in. If anyone as more thoughts about stage-hooks, now is the time.
Looking forward to see what we come up with. Well designed stage-hooks could be a wonderful thing.
Opened a new ticket for it #71.
I guess my main thought there is if the stage hooks are under consideration and hypothetically do get implemented, would addPageContext
be better suited as an on*
hook for consistency?
from vike.
Yes, once/if we go with stage-hooks, the plan is to then deprecate addPageContext
.
from vike.
Every hook is now a stage hook. I.e. addPageContext()
is now onBeforeRender()
.
Thanks for all the lovely feedback.
from vike.
Related Issues (20)
- App crashed - tried to load a non existent page (other non existent pages just show 404) HOT 1
- HRM issue after changing one character in default setup HOT 8
- Vike Bug during vitest run HOT 5
- "Stumbled upon a Vike bug" when using Vanilla Extract ^4.0.4 HOT 4
- Ignore list for file crawling
- storybook-vike HOT 3
- Vike Bug during SSR generation HOT 10
- Query Regarding Page Navigation in Vike Software
- Client-only guard() hook HOT 3
- crash app in build mode after update vike from 0.4.165 to 0.4.168 HOT 1
- How to set scrollPosition to auto HOT 6
- Bug reported due to HMR overlay HOT 4
- UncaughtException issue HOT 1
- history.state.triggedby and history.state.triggeredby HOT 7
- New hook `onRequestBegin()`
- Styled component's classname did not match the server issue with HMR
- New CLI commands `$ vike routes`, `$vike pages`, and `$ vike config`
- Vike StrictMode
- `urlParsed` removes trailing slash HOT 7
- Offer `href` in `urlParsed` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vike.