You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Flatten pageContext: merge all nested pageContext values directly onto pageContext => for a "think-free" pageContext that "just works".
Source information at pageContext.source: where the value comes from.
Precise access at pageContext.from: for conflict-free access.
Behind the scene, pageContext is a Proxy: upon property access the proxy goes through all sources (in a sensible order) and returns the first value it finds.
Examples
pageContext.user
pageContext.from.request.user (equivalent value, assuming there isn't any conflict)
pageContext.source.user: Source (see Source down below)
Resolve conflicts. (That's why pageContext.from needs to hold value.)
Config validation.(E.g. Config document.title defined at ${pageContext.from.configsCumulative.document.values[i].definedAt} should be a string.)
Debug. (That's the only purpose of pageContext.from.config[configFilePath] and pageContext.from.hook[hookFilePath].)
Data Structures
// pageContext.source: Record<string, Source>typeSource=SourceConfigs|SourceHooks|SourceRenderFailure|SourceInternal|SourceRequesttypeSourceInternal={type: 'internal'value: unknown}typeSourceRequest={type: 'request'value: unknown}typeSourceRenderFailure={type: 'renderFailure'renderCount: numbersource: Source}typeSourceHooks={type: 'hooks'value: unknown,// e.g. `{ product: { name: 'iPhone', price: '499' } }`hookName: string// hook name e.g. 'data'definedAt: string}typeSourceConfigs=|SourceConfigsOverridable|SourceConfigsCumulative|SourceConfigsComputed/* Potential upcoming feature: resolve cumulative values at config-time instead of runtime, in order to save KBs on the client-side. | SourceConfigsResolved */typeSourceConfigsOverridable={type: 'configsOverridable'value: unknown,definedAt: string}typeSourceConfigsCumulative={type: 'configsCumulative'values: {value: unknown,definedAt: string}[]}typeSourceConfigsComputed={type: 'configsComputed'value: unknown}
Plan
pageContext
: merge all nestedpageContext
values directly ontopageContext
=> for a "think-free"pageContext
that "just works".pageContext.source
: where the value comes from.pageContext.from
: for conflict-free access.Behind the scene,
pageContext
is aProxy
: upon property access the proxy goes through all sources (in a sensible order) and returns the first value it finds.Examples
pageContext.user
pageContext.from.request.user
(equivalent value, assuming there isn't any conflict)pageContext.source.user: Source
(seeSource
down below)pageContext.Page: Component
pageContext.from.config[configFilePath].Page: Component
pageContext.from.configsOverridable.Page: SourceConfigsOverridable
pageContext.source.Page: Source
pageContext.passToClient: string
pageContext.from.configsCumulative.passToClient: SourceConfigsCumulative
pageContext.from.config[configFilePath].passToClient: string
pageContext.source.passToClient: Source
pageContext.isClientSideRenderable:
pageContext.from.configsComputed.isClientSideRenderable: SourceConfigsComputed
pageContext.source.isClientSideRenderable: Source
pageContext.data: Data
pageContext.from.hooks.data: SourceHooks
pageContext.from.hook[hookFilePath].data: Data
pageContext.source.data: Source
pageContext.locale: string
pageContext.from.renderFailure[0].from.hooks.locale
(see Make originalpageContext
accessible to error page #1112)pageContext.from.renderFailure[0].from.hook[hookFilePath].locale
pageContext.source.locale: Source
pageContext.pageId
as well as:pageContext.from.internal.pageId
pageContext.source.pageId: Source
Also:
pageContext.sources[0].Layout: Source
pageContext.sources[1].Layout: Source
Use cases
pageContext
. (No need for the user to setpageContextInit
anymore.)pageContext
of failed rendering, see Make originalpageContext
accessible to error page #1112.pageContext.from
needs to holdvalue
.)Config document.title defined at ${pageContext.from.configsCumulative.document.values[i].definedAt} should be a string
.)pageContext.from.config[configFilePath]
andpageContext.from.hook[hookFilePath]
.)Data Structures
See also
pageContext
from previous render attempts accessible #1846pageContext
accessible to error page #1112vike/vike/client/client-routing-runtime/renderPageClientSide.ts
Line 297 in bd49cc6
The text was updated successfully, but these errors were encountered: