Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a04412c
[not ready for review] Attempt to create flight config for Meta
alunyov Oct 25, 2023
9bf0006
add fb flight configs to bundles
alunyov Oct 25, 2023
ad3123c
Fix build for Meta-only flight config
alunyov Oct 25, 2023
2140757
update config
alunyov Oct 25, 2023
3edeec4
moar changes to inlineHostConfig
alunyov Oct 25, 2023
c992b7a
update inlineHostConfig for dom-fb
alunyov Oct 27, 2023
cb25bf3
Build ReactSharedSubset for FB
alunyov Oct 27, 2023
1271ac0
Update scheduleWork
alunyov Oct 30, 2023
42bc05d
update snapshot
alunyov Oct 30, 2023
f0cd159
Update ReactSharedSubset for FB
alunyov Oct 31, 2023
e87b2b7
add client config
alunyov Nov 1, 2023
ec1160f
do not use `import`
alunyov Nov 1, 2023
8a9f150
a little more clean-up. and reduce the public API to one that we can …
alunyov Nov 5, 2023
e14b1b4
update to resolver clientreference metada
alunyov Nov 5, 2023
8e1e005
more updates to configs
alunyov Nov 5, 2023
95b2c10
Add TODO for ServerReferences impl for now
alunyov Nov 6, 2023
6fc1aa4
renaming of some of the load/require modules types
alunyov Nov 10, 2023
455b835
fix configs
alunyov Nov 10, 2023
c867c58
update client reference types
alunyov Nov 11, 2023
bcdbece
update bundles config
alunyov Nov 11, 2023
b62b35c
keep only minimal tests that covers supported cases
alunyov Nov 12, 2023
6f0e516
rename test to internal
alunyov Nov 12, 2023
87462eb
small refeactoring
alunyov Nov 12, 2023
242d607
moving things around, adding experimental config for dom-fb
alunyov Nov 13, 2023
36eca50
update inlineHostConfigs
alunyov Nov 13, 2023
1399881
update ReactSharedSubsetFB
alunyov Nov 13, 2023
3d6466c
more details in error messages
alunyov Nov 13, 2023
d6fc44b
handle feature flags
alunyov Nov 13, 2023
cec5500
WIP with new destination interface
alunyov Nov 13, 2023
6f3e799
fix flow/expose requested reference keys
alunyov Nov 14, 2023
456eb39
small refactoring
alunyov Nov 14, 2023
53e2503
Destination interface
alunyov Nov 14, 2023
bcaed1d
expose seen client components
alunyov Nov 15, 2023
89d6e15
renaming things for consistency
alunyov Nov 15, 2023
32c0389
Implement a polyfilled version of byteLengthOfChunk
alunyov Nov 17, 2023
0ebf40c
remove console.log
alunyov Nov 17, 2023
faa9d19
provide impl for byteLengthOfChunk via config
alunyov Nov 18, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement a polyfilled version of byteLengthOfChunk
  • Loading branch information
alunyov committed Nov 17, 2023
commit 32c03890acacf60ab931b51f5da15f663c47b72f
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Destination {
if (!this.#controller) {
throw new Error('Expected a controller.');
}
console.log('flushing', this.#buffer);
this.#controller.enqueue(this.#buffer);
this.#buffer = '';
}
Expand Down Expand Up @@ -308,6 +309,42 @@ describe('ReactFlightDOM for FB', () => {
expect(container.innerHTML).toBe('<p>Hello World</p>');
});

it('should render long strings', async () => {
// Model
const longString = 'Lorem Ipsum ❤️ '.repeat(100);

function RootModel() {
return {text: longString};
}

// View
function Message({response}) {
return <p>{use(response).text}</p>;
}
function App({response}) {
return (
<Suspense fallback={<h1>Loading...</h1>}>
<Message response={response} />
</Suspense>
);
}
const destination = new Destination();
ReactServerDOMServer.renderToDestination(destination, <RootModel />);
const response = ReactServerDOMClient.createFromReadableStream(
destination.stream,
{
moduleMap,
},
);

const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<App response={response} />);
});
expect(container.innerHTML).toBe('<p>' + longString + '</p>');
});

// TODO: `registerClientComponent` need to be able to support this
it.skip('throws when accessing a member below the client exports', () => {
const ClientModule = clientExports({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,45 @@ import type {
BinaryChunk,
} from '../ReactServerStreamConfigFB';

export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
if (typeof chunk !== 'string') {
// eslint-disable-next-line react-internal/prod-error-codes
throw new Error('byteLengthOfChunk: binary chunks are not supported.');
}
return byteLengthImpl(chunk);
}

// TODO: We need to replace this with native implementation, once its available on Hermes
function byteLengthImpl(chunk: string) {
/**
From: https://datatracker.ietf.org/doc/html/rfc3629
Char. number range | UTF-8 octet sequence
(hexadecimal) | (binary)
--------------------+---------------------------------------------
0000 0000-0000 007F | 0xxxxxxx
0000 0080-0000 07FF | 110xxxxx 10xxxxxx
0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
*/
let byteLength = chunk.length;
for (let i = chunk.length - 1; i >= 0; i--) {
const code = chunk.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) {
byteLength++;
} else if (code > 0x7ff && code <= 0xffff) {
byteLength += 2;
}
if (code >= 0xdc00 && code <= 0xdfff) {
// It is a trail surrogate character.
// In this case, the code decrements the loop counter i so
// that the previous character (which should be a lead surrogate character)
// is also included in the calculation.
i--;
}
}
return byteLength;
}

export interface Destination {
beginWriting(): void;
write(chunk: Chunk | PrecomputedChunk | BinaryChunk): void;
Expand Down