Skip to content

Commit 407e9b6

Browse files
authored
fix: drop getAsString from HeadContext (#41)
@ascorbic Is Impala still maintained? I happened to have some small projects that `@impala/preact` just perfectly fit the need. I noticed that `preact-render-to-string` is being included in the client bundle, which is weird. I dug around and noticed that this is used in the `HeadContext`'s `getAsString` method, which is not being used at all: https://github.com/search?q=repo%3Aascorbic%2Fimpala%20getAsString&type=code I guess the `getAsString` was added for SSR, but later the SSR for `<head />` has been moved to `entry-server` instead, which made `getAsString` obsolete: - preact - https://github.com/ascorbic/impala/blob/74a4ab04744e8a539a3a7ec1225753c36ac040df/packages/preact/src/entry-server.tsx#L25 - react - https://github.com/ascorbic/impala/blob/74a4ab04744e8a539a3a7ec1225753c36ac040df/packages/react/src/entry-server.tsx#L60 The PR removes the `getAsString` method from `HeadContext`, preventing `preact-render-to-string` and `react-dom/server` from being included in the client bundle (they should only be in the server bundle).
1 parent 74a4ab0 commit 407e9b6

File tree

2 files changed

+0
-10
lines changed

2 files changed

+0
-10
lines changed

packages/preact/src/head-context.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createContext, VNode } from "preact";
2-
import render from "preact-render-to-string";
32

43
class HeadProvider {
54
private head: VNode<any>[] = [];
@@ -30,10 +29,6 @@ class HeadProvider {
3029
public getHead() {
3130
return this.head;
3231
}
33-
34-
public getAsString() {
35-
return render(<>{...this.head}</>);
36-
}
3732
}
3833

3934
const headProvider = new HeadProvider();

packages/react/src/head-context.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { createContext, ReactElement, ReactNode } from "react";
2-
import { renderToStaticMarkup } from "react-dom/server";
32

43
class HeadProvider {
54
private head: React.ReactElement[] = [];
@@ -30,10 +29,6 @@ class HeadProvider {
3029
public getHead() {
3130
return this.head;
3231
}
33-
34-
public getAsString() {
35-
return renderToStaticMarkup(<>{...this.head}</>);
36-
}
3732
}
3833

3934
const headProvider = new HeadProvider();

0 commit comments

Comments
 (0)