mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 23:06:10 +03:00
Don't call user's init function during pre-rendering phase.
This commit is contained in:
parent
fe6e046610
commit
defe0beb33
3
index.js
3
index.js
@ -9,7 +9,8 @@ module.exports = function pagesInit(
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
let app = mainElmModule.init({
|
||||
flags: {
|
||||
secrets: null
|
||||
secrets: null,
|
||||
isPrerendering: navigator.userAgent.indexOf("Headless") >= 0,
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -254,6 +254,17 @@ init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel fla
|
||||
case contentCache of
|
||||
Ok okCache ->
|
||||
let
|
||||
phase =
|
||||
case Decode.decodeValue (Decode.field "isPrerendering" Decode.bool) flags of
|
||||
Ok True ->
|
||||
Prerender
|
||||
|
||||
Ok False ->
|
||||
Client
|
||||
|
||||
Err _ ->
|
||||
Client
|
||||
|
||||
( userModel, userCmd ) =
|
||||
initUserModel maybePagePath
|
||||
|
||||
@ -284,6 +295,7 @@ init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel fla
|
||||
, url = url
|
||||
, userModel = userModel
|
||||
, contentCache = contentCache
|
||||
, phase = phase
|
||||
}
|
||||
, cmd
|
||||
)
|
||||
@ -297,6 +309,7 @@ init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel fla
|
||||
, url = url
|
||||
, userModel = userModel
|
||||
, contentCache = contentCache
|
||||
, phase = Client
|
||||
}
|
||||
, Cmd.batch
|
||||
[ userCmd |> Cmd.map UserMsg
|
||||
@ -333,9 +346,15 @@ type alias ModelDetails userModel metadata view =
|
||||
, url : Url.Url
|
||||
, contentCache : ContentCache metadata view
|
||||
, userModel : userModel
|
||||
, phase : Phase
|
||||
}
|
||||
|
||||
|
||||
type Phase
|
||||
= Prerender
|
||||
| Client
|
||||
|
||||
|
||||
update :
|
||||
String
|
||||
->
|
||||
@ -524,7 +543,20 @@ application config =
|
||||
\msg outerModel ->
|
||||
case outerModel of
|
||||
Model model ->
|
||||
update config.canonicalSiteUrl config.view config.pathKey config.onPageChange config.toJsPort config.document config.update msg model
|
||||
let
|
||||
userUpdate =
|
||||
case model.phase of
|
||||
Prerender ->
|
||||
noOpUpdate
|
||||
|
||||
Client ->
|
||||
config.update
|
||||
|
||||
noOpUpdate =
|
||||
\userMsg userModel ->
|
||||
( userModel, Cmd.none )
|
||||
in
|
||||
update config.canonicalSiteUrl config.view config.pathKey config.onPageChange config.toJsPort config.document userUpdate msg model
|
||||
|> Tuple.mapFirst Model
|
||||
|> Tuple.mapSecond (Cmd.map AppMsg)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user