wordpress-playground icon indicating copy to clipboard operation
wordpress-playground copied to clipboard

Doc: Explain what are isomorphic packages

Open adamziel opened this issue 3 years ago • 4 comments

Most playground packages aim to run both in the browser and in Node.js. Let's find a good place in the documentation to talk about that and discuss the upsides (like portability) and downsides (like inability to use browser– or node– specific APIs). Let's also share a few examples of isomorphic and non-isomorphic code.

adamziel avatar Jun 02 '23 15:06 adamziel

Another term I've seen used is "universal", for JavaScript modules that can run in the browser and server side.

The concept will probably come up again in relation to Blueprint steps. Currently, the importFile step uses DOMParser to interact with WP Importer's admin screens, which means it's not universal/isomorphic - it doesn't run in Node.js without importing JSDOM. Rewriting it to be universal is not trivial, but the end result will likely be more efficient to call WP Importer's functions directly instead of navigating HTML/DOM structure.

That makes me wonder how prevalent browser-specific code will be in user-written blueprints.

I think people are hearing more about isomorphic or non-isomorphic code in relation to React server/client components and Next.js use client directive. I wonder what are the similarities and differences.

eliot-akira avatar Jun 03 '23 19:06 eliot-akira

Currently, the importFile step uses DOMParser to interact with WP Importer's admin screens

I'd love to get rid of the DOMParser dependency. Ideally it would only call PHP code. An ideal rewrite would just call the same functions as the importer. Here's a few other ideas, just for fun:

  • Use a POST request authenticated as admin with the correct nonce
  • Replace DOMParser with WP_HTML_Tag_Processor form WordPress

I don't love either so calling the importer functions it is for now

That makes me wonder how prevalent browser-specific code will be in user-written blueprints.

Good question! At the moment, I'm not sure whether it is even possible to put anything browser-specific in a custom blueprint. Can you think of anything?

Think people are hearing more about isomorphic or non-isomorphic code in relation to React server/client components and Next.js use client directive. I wonder what are the similarities and differences.

That's a good one. I'll toy with this idea for a bit.

adamziel avatar Jun 05 '23 23:06 adamziel

Hi, I’d like to work on this issue. Can you assign it to me?

amannex avatar Apr 02 '26 16:04 amannex

The PHP.wasm package guide explains its shared API and adapters, with tradeoffs later in the page (lines 56–93).

fellyph avatar Sep 30 '26 12:09 fellyph