Skip to content

Broken using SSR - Hydrogen #888

@jacksontriffon

Description

@jacksontriffon

Many frameworks these days are migrating to a server-side renderred approach with their apps - Since loadDefaultJapaneseParser() requires the window object to load, it's currently unusable on Hydrogen.

Below is a screenshot of a mock Hydrogen store which breaks when using any parser.
ReferenceError: window is not defined

Image

Steps to reproduce:

  1. Create a new Hydrogen storefront.

    npm create @shopify/hydrogen@latest

    In your terminal, create a new Hydrogen project using example data from Mock.shop
    https://shopify.dev/docs/storefronts/headless/hydrogen/getting-started

  2. Run the dev serverAnchor link to section titled "Step 2: Run the dev server"
    After installation, open your new project and start the dev server:

    cd hydrogen-quickstart
    shopify hydrogen dev
    

    Once the dev server is running, open http://localhost:3000/ in your browser and you'll see Mock.shop

  3. Add budoux to the project.

    npm install budoux
  4. Navigate to file /app/routes/_index.tsx (Home page)

  5. Update the loader function by adding the parser:

    export async function loader(args: LoaderFunctionArgs) {
      const parser = loadDefaultJapaneseParser();
    
      // Start fetching non-critical data without blocking time to first byte
      const deferredData = loadDeferredData(args);
    
      // Await the critical data required to render initial state of the page
      const criticalData = await loadCriticalData(args);
    
      return defer({...deferredData, ...criticalData});
    }
  6. Open http://localhost:3000/ in your browser and you'll see the error.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions