@apollo/client-react-streaming
Advanced tools
Comparing version 0.11.8 to 0.11.9
@@ -16,3 +16,7 @@ import { renderToString } from 'react-dom/server'; | ||
let currentlyStreaming = false; | ||
let tailOfLastChunk = ""; | ||
const textDecoder = new TextDecoder(); | ||
const textEncoder = new TextEncoder(); | ||
const HEAD_END = "</head>"; | ||
const KEEP_BYTES = HEAD_END.length; | ||
const transformStream = new TransformStream({ | ||
@@ -25,7 +29,7 @@ async transform(chunk, controller) { | ||
if (!headInserted) { | ||
const content = textDecoder.decode(chunk, { stream: true }); | ||
const index = content.indexOf("</head>"); | ||
const content = tailOfLastChunk + textDecoder.decode(chunk, { stream: true }); | ||
const index = content.indexOf(HEAD_END); | ||
if (index !== -1) { | ||
const insertedHeadContent = content.slice(0, index) + await renderInjectedHtml() + content.slice(index); | ||
controller.enqueue(new TextEncoder().encode(insertedHeadContent)); | ||
controller.enqueue(textEncoder.encode(insertedHeadContent)); | ||
currentlyStreaming = true; | ||
@@ -37,8 +41,7 @@ setImmediate(() => { | ||
} else { | ||
controller.enqueue(chunk); | ||
tailOfLastChunk = content.slice(-KEEP_BYTES); | ||
controller.enqueue(textEncoder.encode(content.slice(0, -KEEP_BYTES))); | ||
} | ||
} else { | ||
controller.enqueue( | ||
new TextEncoder().encode(await renderInjectedHtml()) | ||
); | ||
controller.enqueue(textEncoder.encode(await renderInjectedHtml())); | ||
controller.enqueue(chunk); | ||
@@ -45,0 +48,0 @@ currentlyStreaming = true; |
{ | ||
"name": "@apollo/client-react-streaming", | ||
"version": "0.11.8", | ||
"version": "0.11.9", | ||
"repository": { | ||
@@ -117,3 +117,3 @@ "url": "git+https://github.com/apollographql/apollo-client-nextjs.git" | ||
"scripts": { | ||
"build": "rimraf dist; tsup", | ||
"build": "rimraf dist .built; tsup && touch .built", | ||
"test": "concurrently -c auto \"yarn:test:*(!base) $@\"", | ||
@@ -126,3 +126,2 @@ "test:base": "TSX_TSCONFIG_PATH=./tsconfig.tests.json node --import tsx/esm --no-warnings --test \"$@\" src/**/*.test.(ts|tsx)", | ||
"prepublishOnly": "yarn pack -o attw.tgz && attw attw.tgz && rm attw.tgz && yarn run test", | ||
"postpublish": "touch .published", | ||
"test-bundle": "yarn test-bundle:attw && yarn test-bundle:package && yarn test-bundle:publint && yarn test-bundle:shape", | ||
@@ -129,0 +128,0 @@ "test-bundle:attw": "attw --pack .", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
725914
5998