How to use the inferno-server.renderToStaticMarkup function in inferno-server

To help you get started, we’ve selected a few inferno-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github infernojs / inferno / packages / inferno-server / __tests__ / observer.spec.server.jsx View on Github external
it('does not views alive when using static + string rendering', function() {
    useStaticRendering(true);

    let renderCount = 0;
    const data = mobx.observable({
      z: 'hi'
    });

    const TestComponent = observer(function testComponent() {
      renderCount++;
      return <div>{data.z}</div>;
    });

    const output = renderToStaticMarkup();

    data.z = 'hello';

    expect(output).toBe('<div>hi</div>');
    expect(renderCount).toBe(1);

    expect(getDNode(data, 'z').observers.length).toBe(0);

    useStaticRendering(false);
  });
});
github infernojs / inferno / packages / inferno-server / __tests__ / creation.spec.server.js View on Github external
it(test.description, () => {
      const container = document.createElement('div');
      const vDom = test.template('foo');
      const output = renderToStaticMarkup(vDom);

      document.body.appendChild(container);
      container.innerHTML = output;
      expect(output).toBe(test.result);
      document.body.removeChild(container);
    });
  });
github infernojs / inferno / packages / inferno-server / __tests__ / props-context.spec.server.jsx View on Github external
it('stateless has context as 2nd argument', () =&gt; {
    function TestChild(props, context) {
      return <p>{context.testContext}</p>;
    }

    const output = renderToStaticMarkup(
      
        
      
    );
    expect(output).toBe('<p>context-works</p>');
  });
github infernojs / inferno / packages / inferno-server / __tests__ / creation.spec.server.jsx View on Github external
it(test.description, () => {
      const container = document.createElement('div');
      const vDom = test.template('foo');
      const output = renderToStaticMarkup(vDom);

      document.body.appendChild(container);
      container.innerHTML = output;
      expect(output).toBe(test.result);
      document.body.removeChild(container);
    });
  });
github infernojs / inferno / packages / inferno-server / __tests__ / creation.spec.server.jsx View on Github external
}

        render() {
          return (
            <div>
              {this.state.foo}
              
            </div>
          );
        }
      }

      const container = document.createElement('div');
      const vDom = ;

      const output = renderToStaticMarkup(vDom);

      document.body.appendChild(container);
      container.innerHTML = output;
      expect(output).toBe('<div>bar2<div>bar2</div></div>');
      document.body.removeChild(container);
    });
  });
github nightwolfz / inferno-starter / server / middleware / render.js View on Github external
const renderProps = match(routes, ctx.url)
  const bundleURL = config.server.DEV ? `//localhost:2002` : ''

  if (renderProps.redirect) {
    return ctx.redirect(renderProps.redirect)
  }

  if (config.server.SSR) {
    try {
      await onEnter(renderProps, ctx.context)
    } catch(error) {
      throw error
    }
  }

  const components = config.server.SSR ? renderToStaticMarkup(
    
      
    
  ) : ''

  ctx.body = indexHTML
    .replace(/{bundleURL}/g, bundleURL)
    .replace('{title}', ctx.context.state.common.title)
    .replace('{state}', JSON.stringify(ctx.context.state, null, 2))
    .replace('{children}', components)
}
github slupjs / slup / packages / Site / src / server.ts View on Github external
app.get('*', (req, res) => {
  /** Generate props for the mathing components in the router */
  const props = matchPath(routes, req.url)
  const App =  createElement(StaticRouter, props)
  const MatchURL = URLs.filter(item => item.url == req.url)[0]
  
  /** Render to string the generated JSX tree */
  const JSX = renderToStaticMarkup(App)

  /** Extract html, css string, plus an ids array for hydratation */
  const { css, html, ids } = SSR.extract(JSX)
  const IDs = JSON.stringify(ids)
  
  /** Render the page to the user based on the template */
  res.send(
    TEMPLATE
      .replace(/\r?\n|\r/g, '')
      .replace('{{TITLE}}', MatchURL ? MatchURL.title : 'Page Not Found')
      .replace('{{CSS}}', css)
      .replace('{{HTML}}', html)
      .replace('{{IDS}}', IDs)
  )
})
github rtsao / hokusai / generator / server-render.js View on Github external
function render(pathname, Markup, App, props) {
  const styletron = new StyletronServer();
  const appContent = InfernoServer.renderToString(createElement(App, {pathname, styletron}));
  const styletronSheets = styletron.getStylesheets();
  const markupProps = Object.assign({}, props, {appContent, styletronSheets});
  return '' + InfernoServer.renderToStaticMarkup(createElement(Markup, markupProps));
}
github oreqizer / infernizer / src / server / app.tsx View on Github external
async function app(ctx, next) {
  const root = InfernoServer.renderToString();

  ctx.body = InfernoServer.renderToStaticMarkup();
  ctx.status = 200;
}

inferno-server

Provides methods to render HTML strings from Inferno elements

MIT
Latest version published 5 months ago

Package Health Score

84 / 100
Full package analysis