Skip to content

Blueprints: Isomorphic DOM - DOMParser, FormData, fetch #379

Closed
@eliot-akira

Description

@eliot-akira

From this merged pull request:

@wp-playground/blueprints will need to be smart about providing a Node.js polyfill for new DOMParser() and fetch().

Currently, the following browser globals are found in the blueprints package.


Possible solution: Prepare a proxy module/package that exports native DOM API for the browser and jsdom for Node.js.

The closest NPM package I found was k0michi/isomorphic-dom, which uses the exports property in its package.json to define browser and server exports.

There's also fetch-shim which does the same for fetch and undici; however, this latter module is now in Node.js core as global fetch since v18 so it's no longer necessary. EDIT: Just learned that global FormData is also available since Node.js v18. So it's only DOMParser that needs to be polyfilled on the server side.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions