Skip to content
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 react-dom@19 #1870

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/jsx.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {useState} from "npm:react";
React DOM is also available as `ReactDOM` in Markdown, or can be imported as:

```js run=false
import * as ReactDOM from "npm:react-dom";
import * as ReactDOM from "npm:react-dom/client";
```

You can define components in JSX modules. For example, if this were `components/Card.jsx`:
Expand Down
2 changes: 1 addition & 1 deletion src/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function reject(root, error) {
}

function displayJsx(root, value) {
return (root._root ??= import("npm:react-dom").then(({createRoot}) => {
return (root._root ??= import("npm:react-dom/client").then(({createRoot}) => {
const node = document.createElement("DIV");
return [node, createRoot(node)];
})).then(([node, client]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/client/stdlib/recommendedLibraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const mapboxgl = () => import("npm:mapbox-gl").then((module) => module.de
export const mermaid = () => import("observablehq:stdlib/mermaid").then((mermaid) => mermaid.default);
export const Plot = () => import("npm:@observablehq/plot");
export const React = () => import("npm:react");
export const ReactDOM = () => import("npm:react-dom");
export const ReactDOM = () => import("npm:react-dom/client");
export const sql = () => import("observablehq:stdlib/duckdb").then((duckdb) => duckdb.sql);
export const SQLite = () => import("observablehq:stdlib/sqlite").then((sqlite) => sqlite.default);
export const SQLiteDatabaseClient = () => import("observablehq:stdlib/sqlite").then((sqlite) => sqlite.SQLiteDatabaseClient); // prettier-ignore
Expand Down
8 changes: 7 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ export function extractNodeSpecifier(path: string): string {
*/
function isBadCommonJs(specifier: string): boolean {
const {name} = parseNpmSpecifier(specifier);
return name === "react" || name === "react-dom" || name === "react-is" || name === "scheduler";
return (
name === "react" ||
name === "react-dom" ||
name === "react-dom/client" ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The /client would never be part of the name; it’s the path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true—I shouldn't have commited that part, it is for node and … I haven't found how to make it work (at all)

name === "react-is" ||
name === "scheduler"
);
}

function shimCommonJs(specifier: string, require: NodeRequire): string {
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export async function getResolvers(page: MarkdownPage, config: ResolversConfig):

// Add React for JSX blocks.
if (page.code.some((c) => c.mode === "jsx")) {
staticImports.add("npm:react-dom");
globalImports.add("npm:react-dom");
staticImports.add("npm:react-dom/client");
globalImports.add("npm:react-dom/client");
}

return {
Expand Down
Loading