-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
fix: document body undefined #518
Changes from all commits
27e96d0
fdc1340
6daaafb
c1bfdfc
84f4d41
43d698d
3f5e88d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ Promise.resolve(new Response(new ReadableStream({ | |
|
||
const injectRscPayload = ( | ||
readable: ReadableStream, | ||
mainJsPath: string, | ||
urlForFakeFetch: string, | ||
) => { | ||
const chunks: Uint8Array[] = []; | ||
|
@@ -93,6 +94,7 @@ globalThis.__WAKU_PREFETCHED__ = { | |
const encoder = new TextEncoder(); | ||
const decoder = new TextDecoder(); | ||
let headSent = false; | ||
let mainJsSent = false; | ||
let data = ''; | ||
let scriptsClosed = false; | ||
const sendScripts = ( | ||
|
@@ -102,6 +104,16 @@ globalThis.__WAKU_PREFETCHED__ = { | |
if (scriptsClosed) { | ||
return; | ||
} | ||
if (!mainJsSent) { | ||
// enqueue `mainJs` first in the body to avoid the document.body undefined error, before we used to inject it in the head which sometimes made it load before the document.body was loaded | ||
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. 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. This should in general send the mainJs one time, weird error, do you know why that happens? 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. Here's the fix #528
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. Yes, what exists then if that does not exist? because as far as I checked the website, there was an alternative. And we need that to be in the body too, so the behaviour is normalized between two environments. 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. it's bundled by vite. it sounds like you just miss a point. do you understand why we get 404? 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. But the error that this PR fixed was reproduced with async too, so I don't think that can always be true and we need to be sure about that. 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. My understanding is that the issue this PR fixed is for HMR in dev mode. I never see such an issue in PRD. 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. Yes it fixed the HMR issue after the refresh in DEV, but I was just concerned how it'd be handled in PRD. That's it. sorry for the confusion. 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. So, my question for you is how Vite+React does it. My guess is that all scripts are in 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. Yep, they're in the head! because the body is always sent in the initial template (index.html) |
||
controller.enqueue( | ||
encoder.encode( | ||
`<script src="${mainJsPath}" async type="module"></script>`, | ||
), | ||
); | ||
mainJsSent = true; | ||
} | ||
|
||
const scripts = chunks.splice(0).map( | ||
(chunk) => | ||
` | ||
|
@@ -337,6 +349,7 @@ export const renderHtml = async ( | |
); | ||
const [copied, interleave] = injectRscPayload( | ||
stream, | ||
`${config.basePath}${config.srcDir}/${config.mainJs}`, | ||
config.basePath + config.rscPath + '/' + encodeInput(ssrConfig.input), | ||
); | ||
const elements: Promise<Record<string, ReactNode>> = createFromReadableStream( | ||
|
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.
This is not related to the PR, but it's a minor change, since we used to set the status 200 even though the
.then
might never work and the promise might reject.So we just bring it when we're sure the promise is getting resolved.